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个回答



使用ES 7,您可以选择将 null_value </ code>指定为字段属性。 但是,无法搜索空值。
请参阅手册 null_value </ code>配置的空值页面和日期数据类型的日期手册页。</ p>
</ div>

展开原文

原文

With ES 7, you have the option of specifying null_value as a field property. Null values cannot be searched, however. See the manual page on null-values for null_value configuration and the manual page on dates for the Date datatype.



我不确定为什么 null </ strong>不起作用,我可以在ES 1.7中索引空值,同样< code> IllegalArgumentException [格式无效:“”]; </ code>表示空字符串而不是空值。</ p>

如果您无法控制数据,则需要使用< a href =“https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-malformed.html"rel =”nofollow“> ignore_malformed ,它不会索引日期字段但索引 通常是文件。</ p>
</ div>

展开原文

原文

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.

doubo9799
doubo9799 这很奇怪,你能尝试将ignore_malformed添加到映射吗?
接近 4 年之前 回复
douba4933
douba4933 我控制数据,我已经传递了空值,但显示错误。 我使用相同版本的弹性。
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问