欢迎投稿

今日深度:

Elasticsearch关闭index的自动日期检测,elasticsearchindex

Elasticsearch关闭index的自动日期检测,elasticsearchindex


笔者使用Elasticsearch时遇到了这样一个问题。将mongodb中的历史数据导入到Elasticsearch,成功导入部分数据后报错:

org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9200],
 URI [mongodatabase/user/5ab8a173b107e818709b203c], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse [field294]"}],
"type":"mapper_parsing_exception","reason":"failed to parse [field294]",
"caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: \"\""}},"status":400}

用head查看发现报错提示的字段因为部分字符串是日期格式,被识别为了日期类型,但是这个字段并不全是日期格式的字符串,部分是空字符串,所以就报错了。

查阅官方文档得知可以设置关闭自动日期检测,但是文档中给出的例子是关闭一个指定type自动日期检测的,没有说明如何关闭index的自动日期检测。好在另一处说明了每个index有一个默认type,叫做"_default_",是所有type的原型。那么只要指定这个type关闭自动日期检测,新建的每个type就都会关闭自动日期检测了。

设置方式如下:(这里还设置了中文分词器,因为index只能在创建时设置一次,所有的设置需要放一起发送)



PUT my_index
{
  "mappings": {
    "_default_": {
      "date_detection": false
    }
  }

}

这样设置后,再导入就不会进行自动日期检测啦。

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/32061.html NewsArticle Elasticsearch关闭index的自动日期检测,elasticsearchindex 笔者使用Elasticsearch时遇到了这样一个问题。将mongodb中的历史数据导入到Elasticsearch,成功导入部分数据后报错: org.elasticsearch.client....
相关文章
    暂无相关文章
评论暂时关闭