Hi @dswitzer2 , I’m not an expert about the highlight_query. I tried it at my endpoint but it doesn’t highlight the tokens.
However, if your target is make it clear why the result was returned, we can use search with explain. Here is an example request and the response. We can know the matched tokens and their detailed contributions
# request
POST index_name/_search?explain=true
{
"_source":False,
"query": {
"neural_sparse": {
"text_sparse":{
"query_tokens":{
"hi":1.1,
"hello":1.2
}
}
}
}
}
# response
{'took': 16,
'timed_out': False,
'_shards': {'total': 3, 'successful': 3, 'skipped': 0, 'failed': 0},
'hits': {'total': {'value': 2, 'relation': 'eq'},
'max_score': 4.664844,
'hits': [{'_shard': '[test][2]',
'_node': 'KA-CsRWNRaSyXeGgxn3MhA',
'_index': 'test',
'_id': 'UIB3YI8BrogF1buXrkbW',
'_score': 4.664844,
'_explanation': {'value': 4.664844,
'description': 'sum of:',
'details': [{'value': 0.9710938,
'description': 'Linear function on the text_sparse field for the hi feature, computed as w * S from:',
'details': [{'value': 1.1,
'description': 'w, weight of this function',
'details': []},
{'value': 0.8828125,
'description': 'S, feature value',
'details': []}]},
{'value': 3.6937501,
'description': 'Linear function on the text_sparse field for the hello feature, computed as w * S from:',
'details': [{'value': 1.2,
'description': 'w, weight of this function',
'details': []},
{'value': 3.078125,
'description': 'S, feature value',
'details': []}]}]}},
{'_shard': '[test][2]',
'_node': 'KA-CsRWNRaSyXeGgxn3MhA',
'_index': 'test',
'_id': 'UYB3YI8BrogF1buXskbT',
'_score': 4.6632814,
'_explanation': {'value': 4.6632814,
'description': 'sum of:',
'details': [{'value': 3.3085938,
'description': 'Linear function on the text_sparse field for the hi feature, computed as w * S from:',
'details': [{'value': 1.1,
'description': 'w, weight of this function',
'details': []},
{'value': 3.0078125,
'description': 'S, feature value',
'details': []}]},
{'value': 1.3546876,
'description': 'Linear function on the text_sparse field for the hello feature, computed as w * S from:',
'details': [{'value': 1.2,
'description': 'w, weight of this function',
'details': []},
{'value': 1.1289062,
'description': 'S, feature value',
'details': []}]}]}}]}}