Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add additional attributes to an existing document elasticsearch

How do I add additional attributes to an existing document in Elasticsearch index.

$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}'

This would create a document in the index. How do I add an attribute to the document? Suppose

"new_attribute":"new_value"

which would modify the document as

"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
"new_attribute" :"new_value"
like image 232
user2512324 Avatar asked Aug 27 '13 13:08

user2512324


People also ask

Can you update a document in Elasticsearch?

DescriptioneditEnables you to script document updates. The script can update, delete, or skip modifying the document. The update API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API.

How do I add data to Elasticsearch?

The best way to add data to the Elastic Stack is to use one of our many integrations, which are pre-packaged assets that are available for a wide array of popular services and platforms. With integrations, you can add monitoring for logs and metrics, protect systems from security threats, and more.

How do I get more than 10 results in Elasticsearch?

If a search request results in more than ten hits, ElasticSearch will, by default, only return the first ten hits. To override that default value in order to retrieve more or fewer hits, we can add a size parameter to the search request body.


2 Answers

I think it is possible with the update api. Check this :

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_update_part_of_a_document

and scroll down to "add a new field to the document".

Regards

like image 136
DeH Avatar answered Oct 19 '22 15:10

DeH


I know this is an old post but i think it can be handy

POST /twitter/tweet/1/_update
{
  "doc": {
    "new_attribute":""
  }
}
like image 21
Yonatan Kiron Avatar answered Oct 19 '22 16:10

Yonatan Kiron