Elasticsearch日期字段的默认值

时间:2016-05-12 11:08:16

标签: elasticsearch

我正在使用以下方法在ES中创建动态映射:

{
  "template": "infobox*",
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "string_fields": {
            "match": "*",
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "my_completion_analyzer",
              "fielddata": {
                "format": "disabled"
              },
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed",
                  "ignore_above": 256
                }
              }
            }
          }
        }
      ]
    }
  }
}

因此,每当我索引具有date字段(birthYear)的文档时,它会自动创建一个birthYear类型的字段(date)。因此,每当我没有birthYear时,我会发送一个空字符串'',然后引发异常mapper_parsing_exception, failed to parse [birthYear]

有什么方法可以解决这个问题吗?我可以指定默认值吗?

1 个答案:

答案 0 :(得分:0)

您可以将supervisor:start_child添加到所有ignore_malformed: true字段,也可以全局设置:

date个字段

date

全局设置

  "dynamic_templates": [
    {
      "string_fields": {
        "match": "*",
        "match_mapping_type": "string",
        "mapping": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "whitespace",
          "fielddata": {
            "format": "disabled"
          },
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed",
              "ignore_above": 256
            }
          }
        }
      }
    },
    {
      "date_fields": {
        "match": "*",
        "match_mapping_type": "date",
        "mapping": {
          "type": "date",
          "ignore_malformed": true
        }
      }
    }
  ]