Milan Suthar
Milan Suthar

Reputation: 352

Elastic Dynamic field mapping

 ES version 6.8.12

I want to map all types to a given field in an index, it should store all types of data , instead of bound to specific type. im facing issue when the string is stored in Long type field.

[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\""}}}}}

Upvotes: 0

Views: 1451

Answers (1)

Val
Val

Reputation: 217474

Then you need to pick the text or keyword data type.

In your mapping, you need to set the caller_id_number data type explicitly to one of the above instead of letting Elasticsearch decide for you.

For instance:

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

Note that you can leverage dynamic mappings if you want to automatically set the mapping for some fields:

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

With the dynamic mapping above, all fields starting with caller_ would get automatically mapped as text while specific_field would be mapped as long...

Upvotes: 2

Related Questions