弹性动态场Map

zxlwwiss  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(413)
ES version 6.8.12

我想将所有类型Map到索引中的给定字段,它应该存储所有类型的数据,而不是绑定到特定类型。当字符串存储在长类型字段中时,我面临问题。

[WARN ] 2020-09-14 06:34:36.470 [[main]>worker0] elasticsearch - Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>"5f4632bab98bdd75a267546b", :_index=>"cdrindex", :_type=>"doc", :routing=>nil}, #<LogStash::Event:0x38a5506>], :response=>{"index"=>{"_index"=>"cdrindex", "_type"=>"doc", "_id"=>"5f4632bab98bdd75a267546b", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [caller_id_number] of type [long] in document with id '5f4632bab98bdd75a267546b'", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"For input string: \"Anonymous\""}}}}}
jhkqcmku

jhkqcmku1#

那你得选一个 text 或者 keyword 数据类型。
在Map中,需要设置 caller_id_number 将数据类型显式地设置为上述类型之一,而不是让elasticsearch为您决定。
例如:

PUT your-index
{
  "mappings": {
    "properties": {
      "caller_id_number": {
        "type": "text"
      },
      ...
    }
  }
}

请注意,如果要自动设置某些字段的Map,可以利用动态Map:

PUT your-index
{
  "mappings": {
    "dynamic_templates": [
      {
        "sources": {
          "match": "caller_*",
          "mapping": {
            "type": "text"
          }
        }
      }
    ],
    "properties": {
      "specific_field": {
        "type": "long"
      }
    }
  }
}

在上面的动态Map中,所有字段都以 caller_ 将自动Map为 textspecific_field 将Map为 long ...

相关问题