Elasticsearch- highlighting on both “.keyword” and text fields












0















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>"
]
}









share|improve this question

























  • 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
















0















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>"
]
}









share|improve this question

























  • 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














0












0








0








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>"
]
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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






share|improve this answer
























  • 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
















0














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






share|improve this answer
























  • 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














0












0








0







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word