Hi
I want to highlight individual query string's match result with different pre & post tags.
- Create Index
PUT multilang_index
{
"mappings": {
"dynamic_templates": [
{
"stripped_section_template": {
"path_match": "STRIPPED_SECTION.*",
"mapping": {
"search_analyzer": "index_analyzer",
"analyzer": "index_analyzer",
"type": "text",
"term_vector": "with_positions_offsets"
}
}
}
]
},
"settings": {
"analysis": {
"analyzer": {
"index_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "standard"
}
}
}
}
}
- Index document
POST multilang_index/_doc/1
{
"STRIPPED_SECTION": {
"description": "failure of heart and increase in blood pressure needs to be examined",
"id": 1
}
}
- Perform search query
POST multilang_index/_search
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"fuzziness": "AUTO",
"query": "blood pressure",
"fields": [
"STRIPPED_SECTION.*"
]
}
},
{
"multi_match": {
"fuzziness": "AUTO",
"query": "heart failure",
"fields": [
"STRIPPED_SECTION.*"
]
}
},
{
"multi_match": {
"fuzziness": "AUTO",
"query": "examine",
"fields": [
"STRIPPED_SECTION.*"
]
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"fields": {
"STRIPPED_SECTION.*": {
"type": "fvh",
"pre_tags": [
"<em1>",
"<em2>",
"<em3>"
],
"post_tags": [
"</em1>",
"</em2>",
"</em3>"
]
}
}
}
}
- ACTUAL Output
"highlight" : {
"STRIPPED_SECTION.description" : [
"<em1>failure</em1> of <em3>heart</em3> and increase in <em1>blood</em1> <em2>pressure</em2> needs to be <em2>examined</em2>"
]
}
In ACTUAL Output, random tags assigned to highlighted keywords.
- EXPECTED Output
"highlight" : {
"STRIPPED_SECTION.description" : [
"<em2>failure</em2> of <em2>heart</em2> and increase in <em1>blood</em1> <em1>pressure</em1> needs to be <em3>examined</em3>"
]
}
I am expecting each matched word from one query string should highlighted with same tag
For Ex :
- All match result of 'heart failure' query should have same tag like failure, heart
- All match result of 'blood pressure' query should have same tag like blood, pressure
- All match result of 'examine' query should have same tag like examined
Is there any way to achieve above mentioned behaviour?