Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 too, but 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?

like image 414
Shawn Roller Avatar asked Apr 10 '13 21:04

Shawn Roller


People also ask

How do I index a JSON file?

You can index JSON data as you would any data of the type that you use to store it. In particular, you can use a B-tree index or a bitmap index for SQL/JSON function json_value , and you can use a bitmap index for SQL/JSON conditions is json , is not json , and json_exists .


1 Answers

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

curl -XPOST 'http://jfblouvmlxecs01:9200/test/_doc/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.

2019-07-10: Should be noted that custom mapping types is deprecated and should not be used. I updated the type in the url above to make it easier to see which was the index and which was the type as having both named "test" was confusing.

like image 99
javanna Avatar answered Oct 23 '22 20:10

javanna