duanqiao2006 2016-10-04 09:32
浏览 514

Elasticsearch不允许在日期字段中索引null

I have bellow data to index:

array:6 [▼
  "index" => "my_index"
  "type" => "audit_field"
  "id" => "57f36d28a1dfc"
  "parent" => "57f36d289f1b2"
  "routing" => 318
  "body" => array:19 [▼
     "session_id" => 318
     "trans_seq_no" => 13
     "table_seq_no" => 13
     "field_id" => 65
     "field_name" => "id"
     "new_value" => 45
     "old_value" => 45
     "date_type_new_value" => null
     "date_type_old_value" => null
     "time_type_new_value" => null
     "time_type_old_value" => null
 ]
]

I have defined mapping myself as bellow

array(
    'index' => 'promote_kmp',
    'type' => 'audit_field',
    'body' => [
        'audit_field' => [
            '_source' => [
                'type' => 'string'
            ],
            "_parent" => [
                "type" => "audit_table"
            ],
            'properties' => [
                'session_id'   => array('type' =>  'string'),
                'trans_seq_no' => array('type' =>  'string'),
                'table_seq_no' => array('type' =>  'string'),
                'field_id'     => array('type' =>  'string'),
                'field_name'   => array('type' => 'string'),
                'old_value'    => array(
                    'type' => 'string'
                ),
                'new_value'    => array(
                    'type' => 'string'
                ),
                'date_type_new_value' => array(
                    'type'   => 'date',
                    'format' =>'YYYY-MM-dd HH:mm:ss||YYYY-MM-dd||MM/dd/yyyy||yyyy/MM/dd'
                ),
                'date_type_old_value' => array(
                    'type'   => 'date',
                    'format' =>'YYYY-MM-dd HH:mm:ss||YYYY-MM-dd||MM/dd/yyyy||yyyy/MM/dd'
                ),
                'time_type_new_value' => array(
                    'type'   => 'date',
                    'format' => 'HH:mm:ss'
                ),
                'time_type_old_value' => array(
                    'type'   => 'date',
                    'format' => 'HH:mm:ss'
                )
            ]
        ]
    ]
);

But when i wan to index data with null in date field, elasticsearch shows and exception that can't parse date field value with mapping date format types. How to solve this, i have also tried with empty, but not working, and give the same message.

MapperParsingException[failed to parse [date_type_new_value]]; nested: 
MapperParsingException[failed to parse date field [], tried both date format 
[YYYY-MM-dd HH:mm:ss||YYYY-MM-dd||MM/dd/yyyy||yyyy/MM/dd], and timestamp 
number with locale []]; nested: IllegalArgumentException[Invalid format: ""];
  • 写回答

2条回答 默认 最新

  • dsa1234569 2016-10-04 14:11
    关注

    I am not sure why null is not working, I can index null value in ES 1.7, also IllegalArgumentException[Invalid format: ""]; indicates blank string and not null value.

    If you don't have control over the data, you need to use ignore_malformed which will not index the date field but index the document normally.

    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退