我正在尝试将字段映射为nGram和“精确”匹配,并使精确匹配首先出现在搜索结果中。这是对类似问题的解答,但我正努力使其工作。
无论我为“精确”字段指定什么提升值,每次都会得到相同的结果顺序。这是我的字段映射的外观:
"name" : { "type" : "multi_field", "fields" : { "name" : { "type" : "string", "boost" : 2.0, "analyzer" : "ngram" }, "exact" : { "type" : "string", "boost" : 4.0, "analyzer" : "simple", "include_in_all" : false } } }
这就是查询的样子:
{ "query": { "filtered": { "query": { "query_string": { "fields":["name","name.exact"], "query":"Woods" } } } } }
multi_field映射是正确的,但是搜索查询需要像这样更改:
{ "query": { "filtered": { "query": { "multi_match": { # changed from "query_string" "fields": ["name","name.exact"], "query": "Woods", # added this so the engine does a "sum of" instead of a "max of" # this is deprecated in the latest versions but works with 0.x "use_dis_max": false } } } } }
现在,结果将“精确”匹配考虑在内,并加总得分。