【ElasticSearch问题1】建立索引的时候报mapper_parsing_exception

报错日志:
网上写elasticsearch也有很多文章,都写的挺好的,目前想把错误日志以及解决方法写出来,希望一些小伙伴能尽快躲开些问题,把时间花在一些有用的事情上。

错误日志
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "analyzer on field [word] must be set when search_analyzer is set"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [doc]: analyzer on field [word] must be set when search_analyzer is set",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "analyzer on field [word] must be set when search_analyzer is set"
}
},
"status": 400
}

建立索引的条件:

{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "ngram_filter": {
          "type": "ngram",
          "min_gram": 2,
          "max_gram": 20
        }
      },
      "analyzer": {
        "ngram_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "ngram_filter"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "_all": {
        "type": "text",
     **   "index_analyzer": "ngram_analyzer",**
        "search_analyzer": "standard"
      },
      "properties": {
        "word": {
          "type": "text",
         ** "index_analyzer": "ngram_analyzer",**
          "search_analyzer": "standard"
        },
        "definition": {
          "type": "text"
        }
      }
    }
  }
}

为什么呢?因为mappings里有写参数在elasticsearch5版本里不支持了,index_analyzer就不支持了,改成了analyzer,改过来,就好了,可以建立索引成功。

转载于:https://blog.51cto.com/shangdc/2169302

你可能感兴趣的:(【ElasticSearch问题1】建立索引的时候报mapper_parsing_exception)