在Elasticsearch中建立索引时映射异常

Tri*_*ind 2 java elasticsearch

当我尝试索引文档时,我得到以下异常.

Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to parse date field [J], tried both date format [dateOptionalTime], and timestamp number with locale []
Run Code Online (Sandbox Code Playgroud)

这一切都是正确的,但有可能忽略异常并索引其余的字段吗?

Ant*_*sky 9

我认为这可以在不重新索引的情况下通过将"ignore_malformed"标志添加到字段的映射来完成.这是我尝试过的,它有效:

使用"日期"字段创建新索引

POST events 
{
  "mappings" : {
    "dates" : {
      "properties" : {
        "lenient_date" : {
          "type" : "date"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

尝试添加格式错误的日期值

PUT events/dates/1
{
  "lenient_date" : "1/32/2014"
}
Run Code Online (Sandbox Code Playgroud)

结果:解析错误(如预期的那样)

{
   "error": "MapperParsingException[failed to parse [lenient_date]]; nested: MapperParsingException[failed to parse date field [1/32/2014], tried both date format [dateOptionalTime], and timestamp number with locale []]; nested: IllegalArgumentException[Invalid format: \"1/32/2014\" is malformed at \"/32/2014\"]; ",
   "status": 400
}
Run Code Online (Sandbox Code Playgroud)

获取事件/日期/ 1结果:找不到日期(按预期)

{
   "_index": "events",
   "_type": "dates",
   "_id": "1",
   "found": false
}
Run Code Online (Sandbox Code Playgroud)

更改映射以允许格式错误的值

PUT events/dates/_mapping
{
  "dates" : {
    "properties" : {
      "lenient_date" : {
        "type" : "date",
        "ignore_malformed" : true
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

尝试添加相同的错误日期

PUT events/dates/1
{
  "lenient_date" : "1/32/2014"
}
GET events/dates/1
Result: now works
{
   "_index": "events",
   "_type": "dates",
   "_id": "1",
   "_version": 1,
   "found": true,
   "_source": {
      "lenient_date": "1/32/2014"
   }
}
Run Code Online (Sandbox Code Playgroud)

注意:

我正在运行ES版本1.3.2.我还没有检查更新的映射如何影响排序和过滤.