ElasticSearch - cross_fields multi match with fuzzy search

混江龙づ霸主 提交于 2020-12-27 17:04:12

问题


I have documents that represent users. They have fields name and surname.

Let's say I have two users indexed - Michael Jackson and Michael Starr. I want these sample searches to work:

  1. Michael => { Michael Jackson, Michael Starr }
  2. Jack Mich => { Michael Jackson } (incomplete words and reversed order)
  3. Michal Star => { Michael Starr } (fuzzy search)

I tried different queries and got the best results from multi_match query with cross_fields type. There are 2 problems though:

  1. It only finds something when at least one of the two words is complete. If I type Jackson Mich, it finds Michael Jackson but if I type Jack Mich, it doens't find anything (but I want it to find it).
  2. It cannot be set to fuzzy search. I really need the fuzzy search but keep the quality of multi_match with cross_fields type.

In other words, I want to implement Facebook-like people searching.

I'm pretty new to ElasticSearch so maybe I'm missing something obvious. Sorry if I do.


回答1:


Jack Mich type of searches

  • Make sure when you are querying use OR and not AND e.g. Jack OR Mich
  • Also essentially you want to do a partial matching on the fields. For this you need to enable nGrams on these fields (do this in mapping) so that index have matches for partial words

You are using the correct query type. These two should solve your problems.

PS: We all are learning here, doing that together is fun :)




回答2:


To answer your second problem:

It cannot be set to fuzzy search. I really need the fuzzy search but keep the quality of multi_match with cross_fields type.

The cross_fields query does not support fuzzy searching. See the issue on GitHub:

https://github.com/elasticsearch/elasticsearch/issues/6866



来源:https://stackoverflow.com/questions/23916180/elasticsearch-cross-fields-multi-match-with-fuzzy-search

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