【问题标题】:Elasticsearch don't allow indexing null in date fieldElasticsearch 不允许在日期字段中索引 null
【发布时间】:2016-10-04 09:32:07
【问题描述】:

我有以下数据要索引:

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
 ]
]

我已将自己的映射定义如下

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'
                )
            ]
        ]
    ]
);

但是当我想在日期字段中使用 null 索引数据时,elasticsearch 会显示无法解析日期字段值与映射日期格式类型的异常。 如何解决这个问题,我也试过空,但不工作,并给出相同的信息。

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: ""];

【问题讨论】:

    标签: php elasticsearch


    【解决方案1】:

    在 ES 7 中,您可以选择将 null_value 指定为字段属性。但是,无法搜索空值。 请参阅the manual page on null-values 了解null_value 配置和the manual page on dates 了解日期数据类型。

    【讨论】:

      【解决方案2】:

      我不知道为什么 null 不起作用,我可以在 ES 1.7 中索引空值,IllegalArgumentException[Invalid format: ""]; 也表示空字符串而不是空值。

      如果您无法控制数据,则需要使用ignore_malformed,它不会索引日期字段,但会正常索引文档。

      【讨论】:

      • 我可以控制数据,我已经传递了空值,但显示了该错误。我使用相同版本的弹性。
      • 这很奇怪,您可以尝试在映射中添加 ignore_malformed 吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 2013-07-22
      • 1970-01-01
      • 2019-01-21
      相关资源
      最近更新 更多