欢迎光临
我们一直在努力

Elasticsearch:No handler for type [string] declared on field[XXX]

创建索引时报错

curl -X PUT "localhost:9200/ithothub.com?pretty" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 1
    },
    "mappings" : {
        "properties": {
            "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
            },
            "message": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
}
'

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "No handler for type [string] declared on field [message]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: No handler for type [string] declared on field [message]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "No handler for type [string] declared on field [message]"
    }
  },
  "status" : 400
}

原因分析

No handler for type [string] declared on field [message]

之前在老集群可以,估计是Elasticsearch新版本特性,果不其然,Elasticsearch从5.X就引入了text和keyword,其中keyword适用于不分词字段,搜索时只能完全匹配,这时string还保留着。

到了6.X就彻底移除string了。另外,”index”的值只能是boolean变量了。

解决方法

"message": { "type": "text", "index": false }
"message": { "type": "text", "index": false }
curl -X PUT "localhost:9200/ithothub.com?pretty" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 1
    },
    "mappings" : {
        "properties": {
            "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
            },
            "message": {
                "type": "text",
                "index": false
            }
        }
    }
}
'

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "ithothub.com"
}

参考文档

  1. ElasticSearch数据类型–string类型已死, 字符串数据永生
  2. https://www.cnblogs.com/zlslch/p/6619089.html
  3. https://www.elastic.co/guide/en/elasticsearch/reference/6.2/breaking-changes-6.0.html
赞(2) 打赏
转载请注明来源:IT技术资讯 » Elasticsearch:No handler for type [string] declared on field[XXX]

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏