user1733735
user1733735

Reputation: 453

Elastic search update mappings

I have mappings created wrongly for an object in elastic search. Is there a way to update the mappings. The mapping has been created wrongly for type of the object(String instead of double).

Upvotes: 0

Views: 233

Answers (3)

Chitra
Chitra

Reputation: 1404

PUT Mapping API allows you to add/modified datatype in an existing index.

PUT /assets/asset/_mapping
{  
  "properties": {
    "common_attributes.asset_id": {
      "type": "text",
      "fields": {
        "keyword": { 
          "type":  "keyword",
          "doc_values": true,
          "normalizer": "lowercase_normalizer"
        }
      }
    },
  }
}

After updating the mapping, update the existing documents using bulk Update API.

POST /_bulk
{"update":{"_id":"59519","_type":"asset","_index":"assets"}}
{"doc":{"facility_id":491},"detect_noop":false}

Note - Use 'detect_noop' for detecting noop update.

Upvotes: 0

Matthias
Matthias

Reputation: 2785

That's entirely possible, by PUTting the new mapping over the existing one, here are some examples.

Please note, that you will probably need to reindex all your data after you have done this, because I don't think that ES can convert string indexes to double indexes. (what will instead happen is, that you won't find any document when you search in that field)

Upvotes: 0

Priyansh Goel
Priyansh Goel

Reputation: 2660

In general, the mapping for existing fields cannot be updated. There are some exceptions to this rule. For instance:

new properties can be added to Object datatype fields.
new multi-fields can be added to existing fields.
doc_values can be disabled, but not enabled.
the ignore_above parameter can be updated.

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

Upvotes: 1

Related Questions