0

I apologize in advance if this is a basic question, but this is my first time dabbling with ES. How do you locate and index a Json file into ES for indexing?

I've already looked at the ES documentation and questions similar to mine, but none of the approaches listed have worked for me thus far.

Import/Index a JSON file into Elasticsearch

is there any way to import a json file(contains 100 documents) in elasticsearch server.?

I'm using Mac OS, and the cURL command I'm using to _bulk my Json file is this:

 curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"

But, this error pops up:

{
   "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to derive xcontent"
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to derive xcontent"
  },
  "status": 400
}
Community
  • 1
  • 1
MLhacker
  • 1,382
  • 4
  • 20
  • 35

3 Answers3

1

To use the bulk api all json objects in your file should have a line like this:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }

Which specify your index and type names and id of document.

For exmple a file containing below content will index 2 documents with index=test, type=type1 and id=1 and 2 with different field1 values:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "field1" : "value3" }

Then you can run a command like:

curl -s -XPOST 'localhost:9200/_bulk' --data-binary "@accounts.json"
alpert
  • 4,500
  • 1
  • 17
  • 27
  • It appears it is already in that format considering that the Json file is taken directly from the Elastic.co documentation page found in this link: https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html – MLhacker Aug 04 '16 at 21:05
  • Just in case it's not the location that's the issue, I have placed the json file in the same directory as where elasticsearch.bat file is located, and other places throughout the elasticsearch folder, but that doesn't seem to fix the issue. – MLhacker Aug 04 '16 at 21:07
  • I just added it in the post. – MLhacker Aug 04 '16 at 21:32
1

just get postman fromenter image description here https://www.getpostman.com/docs/environments give it the file location with /bank/accounts/_bulk?pretty command.

Piyush Mittal
  • 1,860
  • 1
  • 21
  • 39
0

Figured out what I was wrong. Don't do it on REST service. Import data from the terminal.

MLhacker
  • 1,382
  • 4
  • 20
  • 35