ElasticSearch taking word order into account in match query

你离开我真会死。 提交于 2021-01-27 04:08:07

问题


Suppose that my index have two documents:

  1. "foo bar"
  2. "bar foo"

When I do a regular match query for "bar foo", both documents match correctly but they get equal relevance scores. However, I want the order of words to be significant during scoring. In other words, I want "bar foo" to have a higher score.

So I tried putting my match query inside the must clause of a bool query and included a match_phrase (with the same query string) as the should clause. This seems to score hits correctly, until I do a search with "bar test foo". In that case match_phrase query doesn't seem to match, and the hits are returned with equal scores again.

How can I construct my index/query so that it takes word order into account but does not require all searched words to exist in document?


回答1:


Have a look at SpanNearQuery, it allows specifying order with or without slop (limit of how far the terms should be apart each other).

Elasticsearch documentation is here.




回答2:


Take a look at PhraseSearch. You should combine your current search with a PhraseSearch (boost PhraseSearch a bit higher than regular term matching).

Doc: PhraseSearch



来源:https://stackoverflow.com/questions/27953698/elasticsearch-taking-word-order-into-account-in-match-query

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