elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.1k stars 24.83k forks source link

The function score affects the highlighting effect of the highlighter #107450

Open Viggon opened 7 months ago

Viggon commented 7 months ago

Elasticsearch Version

7.8

Installed Plugins

No response

Java Version

jdk1.8

OS Version

win10

Problem Description

Two queries that are basically the same (the only difference is that function_score is used in one of them) return different highlighting effects 微信图片_20240411144110

Steps to Reproduce

create index: put my_index add data: POST my_index/_doc { "name":"互联互通技术" } DSL with function_score: GET my_index/_search { "query": { "function_score": { "query": { "match_phrase": { "name": { "query": "互联", "slop": 0, "zero_terms_query": "NONE", "boost": 1 } } } } }, "highlight": { "fields": { "name": { "pre_tags": [ "<span class=\"lawRed\" >" ], "post_tags": [ "</span>" ], "highlight_query": { "match_phrase": { "name": { "query": "互联", "slop": 0, "zero_terms_query": "NONE", "boost": 1 } } } } } } } DSL without function_score: GET my_index/_search { "query": { "match_phrase": { "name": { "query": "互联", "slop": 0, "zero_terms_query": "NONE", "boost": 1 } } }, "highlight": { "fields": { "name": { "pre_tags": [ "<span class=\"lawRed\" >" ], "post_tags": [ "</span>" ], "type":"plain" } } } } The highlighting results for the above two statements are different: 微信图片_20240411144110

Logs (if relevant)

No response

elasticsearchmachine commented 6 months ago

Pinging @elastic/es-search (Team:Search)

Viggon commented 6 months ago

Sorry, the above DSL with function_score is wrong, actually it is: GET my_index/_search { "query": { "function_score": { "query": { "match_phrase": { "name": { "query": "互联", "slop": 0, "zero_terms_query": "NONE", "boost": 1 } } } } }, "highlight": { "fields": { "name": { "pre_tags": [ "<span class=\"lawRed\" >" ], "post_tags": [ "</span>" ] } } } }

elasticsearchmachine commented 4 months ago

Pinging @elastic/es-search-relevance (Team:Search Relevance)