弹性搜索优先搜索以搜索词开头的结果

Elastic Search Prioritize search results that begin with the search term

我需要优先显示以搜索词开头的搜索结果。我用了"match_phrase_prefix"。我用了"match_phrase_prefix"。但是没有用。

详情:



In this example I need the first result is the device (Iphone 5c)


使用分析器导致标记化问题。在下面查看您的文档字段是如何被标记化的。

您需要使用关键字分词器。

curl -XGET 'localhost:9200/test/_analyze?analyzer=standard&pretty' -d 'Capa Bumper Iphone 5C' | grep token
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   532  100   511  100    21  32800   1347 --:--:-- --:--:-- --:--:-- 34066
  "tokens" : [ {
    "token" : "capa",
    "token" : "bumper",
    "token" : "iphone",
    "token" : "5c",

在您的映射中添加关键字分词器:

https://www.elastic.co/blog/starts-with-phrase-matching