Reputation: 203
I am trying to update a document in elasticsearch,but instead the document gets deleted
POST /index/type/id/
{
"id":1
"field:"modified"
}
What is the way to update a particular field in a document?The document contains an id field by which it is indexed.
Upvotes: 3
Views: 8428
Reputation: 156
I would recommend reading the elastic search documentation about partial updates.
The simplest form of the update request accepts a partial document as the doc parameter, which just gets merged with the existing document.
Objects are merged together, existing scalar fields are overwritten, and new fields are added.
In your situation, I would use the following aproach:
POST /index/type/id/_update
{
"doc": {
"id": 1
"field: "modified"
}
}
But please keep in mind that this will only modify the id field from inside the document, the document _id will not be modified. If you want to modify the document _id, you will have to delete the current document and create a new one with the id you require.
Upvotes: 7
Reputation: 2097
Do one thing. Export your Elastic search in a file format using the below commands.
sudo npm install elasticsearch-tools -g
es-export-bulk --url http://localhost:9200 --file ~/Desktop/filename.json --index elastic_collection_name
Then open that file and update all the data you want.. Then using the below command import it.
es-import-bulk --url http://localhost:9200 --file ~/Desktop/filename.json
Try it.
Upvotes: 0