Elasticsearch 创建映射问题

Elasticsearch create mapping issue

我关注此博客是为了实现自动完成功能。我尝试创建精确的映射但偶然发现了一些错误。

以下是我预期的映射查询。

curl -XPUT "http://localhost:9200/blurays " -d'
{
   "settings": {
      "analysis": {
         "filter": {
            "nGram_filter": {
               "type": "nGram",
               "min_gram": 2,
               "max_gram": 20,
               "token_chars": [
                  "letter",
                  "digit",
                  "punctuation",
                  "symbol"
               ]
            }
         },
         "analyzer": {
            "nGram_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "lowercase",
                  "asciifolding",
                  "nGram_filter"
               ]
            },
            "whitespace_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "lowercase",
                  "asciifolding"
               ]
            }
         }
      }
   },
   "mappings": {
      "movies": {
         "_all": {
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "whitespace_analyzer"
         },
         "properties": {
            "addToCartUrl": {
               "type": "string",
               "index": "no",
               "include_in_all": false
            },
            "format": {
               "type": "string",
               "index": "not_analyzed"
            },
            "mpaaRating": {
               "type": "string",
               "index": "not_analyzed",
               "include_in_all": false
            },
            "price": {
               "type": "double",
               "include_in_all": false
            }
         }
      }
   }
}'

以下是我遇到的错误:-

analyzer on field [_all] must be set when search_analyzer is set

我使用的是最新版本的 ES,即 2.3,这是 2 年前写的。我刚开始学习 ES。可能的解决方案是什么?

定义 _all 字段时,您需要将 index_analyzer 替换为 analyzer,因为这已经 renamed in 2.0.

     "_all": {
        "analyzer": "nGram_analyzer",
        "search_analyzer": "whitespace_analyzer"
     },

同意,但错误消息可能会更好。

elasticsearch 2.x 中删除了索引分析器。

https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_20_mapping_changes.html#_analyzer_mappings