Learn Hadoop
Learn Hadoop

Reputation: 3060

Elasticsearch 5.4.0 - How to add new field to existing document

In Production, we already had 2000+ documents. we need to add new field into existing document. is it possible to add new field ? How can i add new field to exisitng field

Upvotes: 1

Views: 4127

Answers (2)

Kaustubh Rai
Kaustubh Rai

Reputation: 1

We can also add the new field using curl and directly running the following command in the terminal.

curl -X PUT "localhost:9200/you_index/_mapping/defined_mapping" -H 'Content-Type: application/json' -d '{ "properties":{"field_name" : {"type" : type_of_data}} }' 

Upvotes: 0

Val
Val

Reputation: 217554

You can use the update by query API in order to add a new field to all your existing documents:

POST your_index/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script": {
    "inline": "ctx._source.new_field = 0",
    "lang": "painless"
  }
}

Note: if your new field is a string, change 0 to '' instead

Upvotes: 5

Related Questions