liv2hak
liv2hak

Reputation: 14980

Updating a document in elastic search when the document id is automatically generated

I have the following script which I use to insert json document's into my elastic search database.

for file in /home/ec2-user/Workspace/met_parts/*
 do curl -XPOST "http://localhost:9200/ABCD/met/" -d @$file
done

I have a list of 'n' files inside my met_parts folder each file containing on JSON record as below.

        {
            "Application": "xxxxxxxx", 
            "FirstTime": 1425502958958, 
            "LastHost": "127.0.0.1", 
            "Transactions": "88654"
        }

My met_parts folder gets updated once every hour.So I need to run the above script once every hour.When I do curl -XPOST a second time, I want the existing document to be updated, rather than a new object to be inserted. How do I achieve this? Since I am using XPOST the document id is automatically generated by elastic search.

Upvotes: 1

Views: 89

Answers (1)

bittusarkar
bittusarkar

Reputation: 6357

You cannot update a document without the id. You should create document with id so that you know which document to update later. You can use the following command to index a document with a given id.

POST <index name>/<type name>/<document id>
{
    ...
}

Note that you can also use a string for document id.

Upvotes: 2

Related Questions