0

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

以下是我想要的映射查询。

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。有什么可能的解决方案?

4

2 回答 2

6

定义_all需要替换的字段时index_analyzeranalyzer因为它已在 2.0 中重命名

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

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

于 2016-04-08T13:48:02.847 回答
0

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

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

于 2016-04-08T13:49:15.513 回答