Elasticsearch- highlighting on both “.keyword” and text fields
I am finding issues with highlighting when searching on fields using its complete data.I have used custom analyzers and each field is stored as text and keyword.
I am using whitespace as search analyzer.
My custom analyzer is:
"analysis": {
"filter": {
"indexFilter": {
"type": "pattern_capture",
"preserve_original": "true",
"patterns": [
"([@,$,%,&,!,.,#,^,*]+)",
"([\w,.]+)",
"([\w,@]+)",
"([-]+)",
"(\w+)"
]
}
},
"analyzer": {
"indexAnalyzer": {
"filter": [
"indexFilter",
"lowercase"
],
"tokenizer": "whitespace"
},
"searchAnalyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
My mapping file is :
"field": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "indexAnalyzer",
"search_analyzer": "searchAnalyzer"
}
My query is :
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
my highlight results are :
"highlight": {
"field.keyword": [
"<em>monkey business</em>"
],
"field": [
"<em>monkey</em> <em>business</em>"
]
}
elasticsearch
add a comment |
I am finding issues with highlighting when searching on fields using its complete data.I have used custom analyzers and each field is stored as text and keyword.
I am using whitespace as search analyzer.
My custom analyzer is:
"analysis": {
"filter": {
"indexFilter": {
"type": "pattern_capture",
"preserve_original": "true",
"patterns": [
"([@,$,%,&,!,.,#,^,*]+)",
"([\w,.]+)",
"([\w,@]+)",
"([-]+)",
"(\w+)"
]
}
},
"analyzer": {
"indexAnalyzer": {
"filter": [
"indexFilter",
"lowercase"
],
"tokenizer": "whitespace"
},
"searchAnalyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
My mapping file is :
"field": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "indexAnalyzer",
"search_analyzer": "searchAnalyzer"
}
My query is :
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
my highlight results are :
"highlight": {
"field.keyword": [
"<em>monkey business</em>"
],
"field": [
"<em>monkey</em> <em>business</em>"
]
}
elasticsearch
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14
add a comment |
I am finding issues with highlighting when searching on fields using its complete data.I have used custom analyzers and each field is stored as text and keyword.
I am using whitespace as search analyzer.
My custom analyzer is:
"analysis": {
"filter": {
"indexFilter": {
"type": "pattern_capture",
"preserve_original": "true",
"patterns": [
"([@,$,%,&,!,.,#,^,*]+)",
"([\w,.]+)",
"([\w,@]+)",
"([-]+)",
"(\w+)"
]
}
},
"analyzer": {
"indexAnalyzer": {
"filter": [
"indexFilter",
"lowercase"
],
"tokenizer": "whitespace"
},
"searchAnalyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
My mapping file is :
"field": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "indexAnalyzer",
"search_analyzer": "searchAnalyzer"
}
My query is :
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
my highlight results are :
"highlight": {
"field.keyword": [
"<em>monkey business</em>"
],
"field": [
"<em>monkey</em> <em>business</em>"
]
}
elasticsearch
I am finding issues with highlighting when searching on fields using its complete data.I have used custom analyzers and each field is stored as text and keyword.
I am using whitespace as search analyzer.
My custom analyzer is:
"analysis": {
"filter": {
"indexFilter": {
"type": "pattern_capture",
"preserve_original": "true",
"patterns": [
"([@,$,%,&,!,.,#,^,*]+)",
"([\w,.]+)",
"([\w,@]+)",
"([-]+)",
"(\w+)"
]
}
},
"analyzer": {
"indexAnalyzer": {
"filter": [
"indexFilter",
"lowercase"
],
"tokenizer": "whitespace"
},
"searchAnalyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
My mapping file is :
"field": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "indexAnalyzer",
"search_analyzer": "searchAnalyzer"
}
My query is :
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
my highlight results are :
"highlight": {
"field.keyword": [
"<em>monkey business</em>"
],
"field": [
"<em>monkey</em> <em>business</em>"
]
}
elasticsearch
elasticsearch
edited Nov 19 '18 at 15:44
Piotr Pradzynski
1,72521127
1,72521127
asked Nov 19 '18 at 7:40
M NikeshM Nikesh
557
557
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14
add a comment |
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14
add a comment |
1 Answer
1
active
oldest
votes
I can suggest you such query (analysis & mapping stay the same):
GET /index-53370229/_doc/_search
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "fvh",
"fields": {
"field": {
"matched_fields": [
"field",
"field.keyword"
]
}
}
}
}
The only change is in the highlight section. As a result you will get:
"highlight": {
"field": [
"<em>monkey business</em>"
]
}
I've used matched_fields property about which you can read in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-highlighting.html#matched-fields
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370229%2felasticsearch-highlighting-on-both-keyword-and-text-fields%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I can suggest you such query (analysis & mapping stay the same):
GET /index-53370229/_doc/_search
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "fvh",
"fields": {
"field": {
"matched_fields": [
"field",
"field.keyword"
]
}
}
}
}
The only change is in the highlight section. As a result you will get:
"highlight": {
"field": [
"<em>monkey business</em>"
]
}
I've used matched_fields property about which you can read in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-highlighting.html#matched-fields
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
add a comment |
I can suggest you such query (analysis & mapping stay the same):
GET /index-53370229/_doc/_search
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "fvh",
"fields": {
"field": {
"matched_fields": [
"field",
"field.keyword"
]
}
}
}
}
The only change is in the highlight section. As a result you will get:
"highlight": {
"field": [
"<em>monkey business</em>"
]
}
I've used matched_fields property about which you can read in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-highlighting.html#matched-fields
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
add a comment |
I can suggest you such query (analysis & mapping stay the same):
GET /index-53370229/_doc/_search
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "fvh",
"fields": {
"field": {
"matched_fields": [
"field",
"field.keyword"
]
}
}
}
}
The only change is in the highlight section. As a result you will get:
"highlight": {
"field": [
"<em>monkey business</em>"
]
}
I've used matched_fields property about which you can read in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-highlighting.html#matched-fields
I can suggest you such query (analysis & mapping stay the same):
GET /index-53370229/_doc/_search
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields":
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "fvh",
"fields": {
"field": {
"matched_fields": [
"field",
"field.keyword"
]
}
}
}
}
The only change is in the highlight section. As a result you will get:
"highlight": {
"field": [
"<em>monkey business</em>"
]
}
I've used matched_fields property about which you can read in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-highlighting.html#matched-fields
answered Nov 19 '18 at 22:38
Piotr PradzynskiPiotr Pradzynski
1,72521127
1,72521127
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
add a comment |
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
Can make this change in highlights generic? Because, i have around 100 such fields, I don't think it's a right way to mention all the 100 fields in highlights
– M Nikesh
Nov 20 '18 at 5:53
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
I am afraid that this is not possible to do in more generic way.
– Piotr Pradzynski
Nov 20 '18 at 6:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370229%2felasticsearch-highlighting-on-both-keyword-and-text-fields%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
OK, and what you are expecting to achieve?
– Piotr Pradzynski
Nov 19 '18 at 14:04
I would like to know if there is a way to ignore .keyword file when there's already a hit on text field? There's redundancy in highlight in the above case since same field is highlighted twice.
– M Nikesh
Nov 19 '18 at 14:14