Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 394 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parse_exception - request body is required

#1
I'm trying to insert a `JSON` data file in my `elasticsearch` instance.

`curl -s -H “Content-Type: application/x-ndjson” -XPOST localhost:9200/_bulk —-data-binary “@restaurants.json”; echo`

However, after executing this command I get an error that says

`{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}`

The JSON file basically has an array of the below object.
Only thing is that I've put just one object here to save space. However, there are more than one objects present.

Structure is like given below;

[
{
"address": {
"building": "351",
"coord": [
-73.98513559999999,
40.7676919
],
"street": "West 57 Street",
"zipcode": "10019"
},
"borough": "Manhattan",
"cuisine": "Irish",
"name": "Dj Reynolds Pub And Restaurant",
"grades": [
{
"date": {
"$date": "2014-09-06T00:00:00.000Z"
},
"grade": "A",
"score": 2
},
{
"date": {
"$date": "2013-07-22T00:00:00.000Z"
},
"grade": "A",
"score": 11
},
{
"date": {
"$date": "2012-07-31T00:00:00.000Z"
},
"grade": "A",
"score": 12
},
{
"date": {
"$date": "2011-12-29T00:00:00.000Z"
},
"grade": "A",
"score": 12
}
],
"id": "30191841"
}
]
Reply

#2
I had this same issue in Windows and am posting this here for anyone that comes across the same question with this error referenced.

>{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}

I found at least two causes:

1. cURL doesn't know where the file you are trying to load is:

In this case, make sure to run cURL from the directory where the file is located. Try executing the following command and making sure you see the file.

>more file.json

2. Windows command line DOES NOT support single quotes within the cURL command line:

**BAD**

>curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk' --data-binary '@file.json'

**GOOD**

>curl -H "Content-Type: application/x-ndjson" -XPOST "localhost:9200/_bulk" --data-binary "@file.json"
Reply

#3
I solved it by wrapping the url with quotation mark.

curl -s -H “Content-Type: application/x-ndjson” -XPOST "localhost:9200/_bulk —-data-binary “@restaurants.json”;

Reply

#4
The bulk API requires one document per line, which means you can't have newlines in your documents. Try stripping all the white spaces from the JSON you're submitting. You are also just submit a stream of documents, and not a JSON array of objects. See Bulk API documentation here:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through