Favor exact matches over ngram matches in ElasticSearch when mapping

£可爱£侵袭症+ 提交于 2019-12-05 19:16:23

问题


I have partial matching of words working with ngrams. How can I modify the mapping to always favor exact matches over ngram tokens? I do not want to modify the query. One search box will search multiple types, each with their own fields.

For example, lets say I'm searching job titles, one person has a title of "field engineer", the other a title of "engine technician". If a user searches for "engine", I'd want ES to return the latter as more relevant.

I'm using this mapping almost verbatim: https://stackoverflow.com/a/19874785/978622 -Exception: I'm using an ngram with min of 3 and max of 11 instead of edge ngram

Is it possible to apply a boost/function score to an analyzer? If so I'll apply both the "full_name" and "partial_name" analyzers to my index as well and boost the first.

Edit: I'm using ElasticSearch 1.1.1 and Nest 1.0.0 beta


回答1:


I don't believe there is anyway to apply boosting to an analyzer as you're suggesting.

One thing you can try, is to use the multi field type in your mapping. You could then apply your partial_name analyzer to one version of the field, and your full_name analyzer to the other version.

With this mapping, you could query both fields differently, but combined (perhaps in a bool query), and apply a boost to the query that is being conducted on the full_name analyzed field.



来源:https://stackoverflow.com/questions/23686577/favor-exact-matches-over-ngram-matches-in-elasticsearch-when-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!