【问题标题】:Elasticsearch 2.3 put mapping (Attempting to override date field type) errorElasticsearch 2.3 放置映射(尝试覆盖日期字段类型)错误
【发布时间】:2016-05-27 10:21:28
【问题描述】:

我有一些要存储为字符串的birth_dates。我不打算对数据进行任何查询或分析,我只是想存储它。

我得到的输入数据有很多不同的随机格式,有些甚至包括像(approximate) 这样的字符串。 Elastic 已确定这应该是具有日期格式的日期字段,这意味着当 Elastic 收到像 1981 (approx) 这样的日期时,它会吓坏并说输入格式无效。

我想将日期类型更改为字符串,而不是更改输入日期。

我查看了文档并尝试使用 PUT 映射 API 更新映射,但弹性不断返回解析错误。

根据此处的文档:

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

我试过了:

PUT /sanctions_lists/eu_financial_sanctions/_mapping
{
    "mappings":{
        "eu_financial_sanctions":{
         "properties": {
             "birth_date": {
                 "type": "string", "index":"not_analyzed"
             }
         }
       }
    }
 }

但返回:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters:  [mappings : {eu_financial_sanctions={properties={birth_date={type=string, index=not_analyzed}}}}]"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters:  [mappings : {eu_financial_sanctions={properties={birth_date={type=string, index=not_analyzed}}}}]"
   },
   "status": 400
}

问题摘要

是否可以覆盖elasticsearch自动确定的日期字段,强制字符串为字段类型?

注意

我正在使用 google chrome sense 插件发送请求

弹性搜索版本是 2.3

【问题讨论】:

    标签: elasticsearch elasticsearch-mapping


    【解决方案1】:

    只需从 url 中删除类型引用和映射,您就可以将它们放在请求正文中。 More examples.

    PUT /sanctions_lists
    {
        "mappings":{
            "eu_financial_sanctions":{
             "properties": {
                 "birth_date": {
                     "type": "string", "index":"not_analyzed"
                 }
             }
           }
        }
    }
    

    【讨论】:

    • 我刚刚尝试过PUT /sanctions_lists/_mapping 得到另一个错误"Validation Failed: 1: mapping type is missing;" 如果我不包含“_mapping”,它不会尝试将其存储为文档吗?
    • 为什么不能使用PUT /sanctions_lists?我已将示例链接放在答案中。
    • 因为你的方法是添加一个新类型。我想更新现有字段。我得到"type": "index_already_exists_exception", 然后使用我尝试的链接示例:PUT /sanctions_lists/_mapping/eu_financial_sanctions 并得到错误"type": "illegal_argument_exception", "reason": "mapper [birth_date] of different type, current_type [date], merged_type [string]"
    • 这是预期的。你 can not change type 在 elasticsearch 创建后。您必须为您的字段或 reindex 整个索引使用不同的名称。
    • 看起来我们无法从 >elastic.co/guide/en/elasticsearch/reference/current/… 更新 elasticsearch 2.3 中的映射 >一般情况下,无法更新现有字段的映射。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多