简体   繁体   English

弹性搜索的“match_phrase_prefix”查询问题

[英]Problem with 'match_phrase_prefix' query for elastic search

I have an issue with querying using match_phrase_prefix.我在使用 match_phrase_prefix 进行查询时遇到问题。 P.ex let's say i have a record with display_name = "stack overflow". P.ex 假设我有一条 display_name = "stack overflow" 的记录。 If i query using "stack" or "stack over" it will find the record but not if i try "stack o".如果我使用“stack”或“stack over”查询,它会找到记录,但如果我尝试“stack o”则不会。 I noticed this has been asked before and the issue is with the prefix but i didn't seem to find a proper answer.我注意到之前有人问过这个问题,问题出在前缀上,但我似乎没有找到合适的答案。 Any thoughts?有什么想法吗?

Its returns the documents for stack o , you can follow below example to see it.它返回stack o的文档,您可以按照下面的示例查看它。

Index mapping索引映射

{
  "mappings": {
    "properties": {
      "display_name": {
        "type": "text"
      }
    }
  }
}

Index document索引文件

{
   "display_name" : "stack overflow"
}

Search query搜索查询

{
    "query": {
        "match_phrase_prefix" : {
            "display_name" : {
                "query" : "stack o"
            }
        }
    }
}

And it returns the above-indexed doc它返回上面索引的文档

"hits": [
         {
            "_index": "so-60620921-match-prefix",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.5753642,
            "_source": {
               "display_name": "stack overflow"
            }
         }
      ]

You can even check the official ES doc example where it returns the document for quick brown f .你甚至可以查看官方的 ES 文档示例,它返回quick brown f的文档。

You should try increasing the value of max_expansions (default 50 , here )您应该尝试增加max_expansions的值( 此处为默认50
Be careful not to put it too high either, at the risk of slowing down the query!小心不要把它放得太高,有降低查询速度的风险!

So you can try this:所以你可以试试这个:

{
    "query": {
        "match_phrase_prefix": {
            "display_name": {
                "query": "stack o",
                "max_expansions": 100,
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM