Shawn Roller Shawn Roller - 1 year ago 281
JSON Question

Import/Index a JSON file into Elasticsearch

I am new to Elasticsearch and have been entering data manually up until this point. For example I've done something like this:

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

I now have a .json file and I want to index this into Elasticsearch. I've tried something like this to no success:

curl -XPOST 'http://jfblouvmlxecs01:9200/test/test/1' -d lane.json

How do I import a .json file? Are there steps I need to take first to ensure the mapping is correct?

Answer Source

The right command if you want to use a file with curl is this:

curl -XPOST 'http://jfblouvmlxecs01:9200/test/test/1' -d @lane.json

elasticsearch is schemaless, therefore you don't necessarily need a mapping. If you send the json as it is and you use the default mapping every field will be indexed and analyzed using the standard analyzer.

If you want to interact with elasticsearch through the command line you may want to have a look at the elasticshell which should be a little bit handier than curl.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download