I am seeing some unexplainable behavior with highlighting returning different responses depending on the search text. Below are two examples of nearly identical queries with different search texts. I am not sure how to explain this?
Here is query 1. Notice I am searching for "log" as an exact match in translated_content.
query = {
"from": 0, "size": 5,
'_source': ['translated_title',
'translated_content'],
"query": {"bool": {
"must": [ {"query_string": {"fields": ['translated_content', 'translated_title'],
"query": "translated_content.exact:log"}}
]
}
},
"highlight": {'fields': [{'translated_content': {'number_of_fragments': 0}},
{'translated_title': {'number_of_fragments': 0}}],
"require_field_match": False,
"highlight_query": {"bool": {"must": [{"query_string": {"fields": ['translated_content', 'translated_title'],
"query": "translated_content.exact:log"}}]}}},
}
The response for this is normal, as expected:
_source: {'translated_content': 'Very log i cant even log in', 'translated_title': ''}
highlight: {'translated_content': ['Very <em>log</em> i cant even <em>log</em> in']}
_source: {'translated_content': 'My account log out can not log in...why?', 'translated_title': 'Good'}
highlight: {'translated_content': ['My account <em>log</em> out can not <em>log</em> in...why?']}
Now here is the odd behavior. When I search for a different word, in this case 'image', I get no highlight response field. It is unclear what words return correctly with highlight and which do not.
query = {
"from": 0, "size": 5,
'_source': ['translated_title',
'translated_content'],
"query": {"bool": {
"must": [ {"query_string": {"fields": ['translated_content', 'translated_title'],
"query": "translated_content.exact:image"}}
]
}
},
"highlight": {'fields': [{'translated_content': {'number_of_fragments': 0}},
{'translated_title': {'number_of_fragments': 0}}],
"require_field_match": False,
"highlight_query": {"bool": {"must": [{"query_string": {"fields": ['translated_content', 'translated_title'],
"query": "translated_content.exact:image"}}]}}},
}
Response:
_source: {'translated_content': 'Check this image', 'translated_title': 'Why band my id'}
highlight: None