ElasticSearch error while sending data

I am trying to send JSON to resSearch. I tried using Postman and SOAPUI Data

[{"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}, {"column1": "pqr", "column2": "stu", "column3": "vwx", "column4": "", "column5": ""}] 

I get the following error back

 { "error": { "root_cause": [ { "type": "mapper_parsing_exception", "reason": "failed to parse" } ], "type": "mapper_parsing_exception", "reason": "failed to parse", "caused_by": { "type": "not_x_content_exception", "reason": "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes" } }, "status": 400 } 

But when I send one JSON Ie array

 {"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"} 

Then it works great. I am new to ElasticSearch, so I'm not sure what is going wrong.

+10
source share
8 answers

Try using curly braces first and then name the array. Try it and see if it works.

For instance:

 {root:[1, 2, 3, 4, 5]} 

may work because it is contained within an object.

Even better; while I experimented with JSON.stringify(); I found that it covers arrays in JSON as follows:

 {1, 2, 3, 4, 5} 
+7
source

thanks @ hellol11

It worked when I switched to

  {root : [ {"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}, {"column1": "pqr", "column2": "stu", "column3": "vwx", "column4": "", "column5": ""} ]} 
+6
source

I recently came across this use of curl and it was a simple typo. I did not use the built-in json, but from the file. I forgot to include the @ sign in front of the file name.

 curl -XPUT -H'Content-Type:application/json' localhost:9200/twitter -d@mappings.json 
+3
source

I had this problem inside a Python script (using requests) to try to send POST to ES. The solution was to simply convert the json object to a string using json.dumps()

Example (Python code snippet):

 import json import requests headers={'Content-Type': 'application/json'} data={'hello':'barney'} response = requests.post('https://<my_es_domain>/<my_es_ix>/<my_doc_type>', data=json.dumps(data), headers=headers) 
+2
source

In Windows environment, I solved this problem.

 -d plus double quotation(") 

and backslash surrounding name plus double quote (\ ")

Team>

 curl (more-option) -d "{\"column1\": \"abc\", \"column2\": \"def\", \"column3\": \"dghi\", \"column4\": \"jkl\", \"column5\": \"mno\"}" 
+1
source

In the search for elasticity, if you want to publish bulk data, each list object should be in a new .so line, if you use meaning, then do everything in the "New" line or, using the code, add the newline character \ n ...

0
source

@ JUNG THANKS SO MUCH !!! double slashes quotes made it work !!! I do not have a reputation of 50 or more to comment directly on your answer ... but you are +1. I appreciate him!

0
source

I was getting the same error while trying to publish on elasticsearch, but using js node. I used the node-fetch package to make a PUT request toasticsearch. This was strange because, using the same thing on the postman, I did not get the error, but I got the error on the js node. I originally did:

 const current = { "id" : "123456789" } const options = { method: "POST", headers: { "Content-Type": "application/json" }, body: current } 

It turns out the error was fixed when I changed it to:

 body: JSON.stringify(current) 
0
source

Source: https://habr.com/ru/post/1242329/


All Articles