ElasticSearch查询麻烦

ElasticSearch query trouble

使用下一个默认设置在弹性搜索中创建我的索引后:

{    "autosuggest_destination": {
      "aliases": {},
      "mappings": {
         "destination": {
            "properties": {
               "city": {
                  "type": "string"
               },
               "country": {
                  "type": "string"
               },
               "id": {
                  "type": "string"
               },
               "state": {
                  "type": "string"
               }
            }
         }
      },
      "settings": {
         "index": {
            "creation_date": "1459329252404",
            "number_of_shards": "1",
            "number_of_replicas": "0",
            "version": {
               "created": "1070299"
            },
            "uuid": "_1D7ZW0dQwy9kiKn0kKrLw"
         }
      },
      "warmers": {}    } }

after insert data to index and verified.

I get this problem while trying to search for an auto complete word:

when i try to search for 'new' it founds matches (New York). but if i tries to add a space and first letter after 'new y', it founds nothing. and after it tries to add a space and two letters after 'new yo' it works.

The main problem is understand why the first letter after a word with a space is not a match?

example :

    GET autosuggest_destination/destination/_search {    "query": {
        "match": {
          "city": {
            "query": "new", 
            "type": "phrase_prefix"
          }

           } }

    Result : New York


    GET autosuggest_destination/destination/_search {    "query": {
        "match": {
          "city": {
            "query": "new y", 
            "type": "phrase_prefix"
          }

           } }

    No Result

    GET autosuggest_destination/destination/_search {    "query": {
        "match": {
          "city": {
            "query": "new yo", 
            "type": "phrase_prefix"
          }

           } }

Result : New York

有人知道问题出在哪里吗?


Elasticsearch 在索引文档时使用分析器(默认分析器或自定义分析器),当您搜索某些值时,它将文档拆分为术语,然后它将与您想要搜索的内容进行匹配。
在你的例子中: New York 使用默认分析器进行分析,它将您的文档分成 2 个术语 New、York。
当您搜索 New 时,它会为您找到第一个术语 New,因此它会给您纽约的响应。 如果您按 New Y 搜索,它将搜索分为 2 个词:New, Y 或 New, Yo,它会尝试查找与这 2 个词匹配的文档。您遇到的问题可能来自 max_expansions param.
看这里 http://elasticsearch-users.115913.n3.nabble.com/How-exactly-works-quot-max-expansions-quot-in-match-phrase-prefix-query-td4030146.html 也关于分析仪。

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html

如果我想查询部分单词,例如 "ork" 到(结果执行:纽约) 那么就没有命中。 我在文档中寻找指南,我所能找到的只是将查询更改为通配符,这将允许我这样做。 但我希望使用 phrase_prefix 也只能通过部分单词进行搜索。 那可能吗?