How to insert data into elasticsearch

user1162069 picture user1162069 · Apr 5, 2014 · Viewed 186.1k times · Source

I am new to Elasticearch, and I have been trying for 2 days to insert some data into Elasticearch. I found on Google that there are many pages to help to create an index (I am not clear about "index", does it mean "insert" in other terms?) Then many places give some curl command, and I really don't know where to execute these code lines to insert data. Example:

curl -XPOST "http://[localhost]:9200/indexname/typename/optionalUniqueId" -d '{ "field" : "value" }'

I am using Window 7 and I have installed Java and run elasticsearch successfully. Could anybody show me more details about how to insert data into Elasticearch

Many thanks

Answer

Sabuj Hassan picture Sabuj Hassan · Apr 5, 2014

You have to install the curl binary in your PC first. You can download it from here.

After that unzip it into a folder. Lets say C:\curl. In that folder you'll find curl.exe file with several .dll files.

Now open a command prompt by typing cmd from the start menu. And type cd c:\curl on there and it will take you to the curl folder. Now execute the curl command that you have.

One thing, windows doesn't support single quote around around the fields. So you have to use double quotes. For example I have converted your curl command like appropriate one.

curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/indexname/typename/optionalUniqueId" -d "{ \"field\" : \"value\"}"