在映射时,通过ElasticSearch中的ngram匹配进行匹配 [英] Favor exact matches over ngram matches in ElasticSearch when mapping

查看:1845
本文介绍了在映射时,通过ElasticSearch中的ngram匹配进行匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有部分匹配用ngram工作的单词。如何修改映射以始终支持使用ngram令牌的精确匹配?我不想修改查询。一个搜索框将搜索多个类型,每个都有自己的字段。



例如,让我说我正在搜索职位,一个人的标题为现场工程师,另一个是发动机技术员的称号。如果用户搜索引擎,我希望ES将后者返回更相关。



我几乎逐字地使用这个映射: https://stackoverflow.com/a/19874785/978622
-Exception:我正在使用最小为3的ngram并且最多为11而不是边缘ngram



是否可以对分析仪应用升压/功能分数?如果是这样,我将同时将full_name和partial_name分析器同时应用于我的索引,并提升第一个。



编辑:我使用ElasticSearch 1.1。 1和Nest 1.0.0 beta

解决方案

我不相信无论如何,建议。



您可以尝试一件事是使用多字段键入您的映射。然后,您可以将 partial_name 分析器应用于该字段的一个版本,将 full_name 分析器应用于其他版本。 / p>

使用此映射,您可以不同地查询两个字段,但可以组合(可能在一个bool查询中),并对正在 full_name 分析字段。


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

解决方案

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.

这篇关于在映射时,通过ElasticSearch中的ngram匹配进行匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆