我正在尝试将一个JSON发送到elasticSearch.我尝试过使用Postman和SOAPUI数据是
[{"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}, {"column1": "pqr", "column2": "stu", "column3": "vwx", "column4": "", "column5": ""}]
我收到以下错误
{ "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 }
但是当我发布一个JSON数组时
{"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}
然后它工作正常.我是ElasticSearch的新手,所以不确定出了什么问题.
首先尝试使用花括号,然后命名数组.试试看,看看它是否有效.
例如:
{root:[1, 2, 3, 4, 5]}
可能会工作,因为它包含在一个对象中.
更好; 在我进行实验时JSON.stringify();
,我发现它将数组转换为JSON,如下所示:
{1, 2, 3, 4, 5}
谢谢@ hellol11
当我换到时它起作用了
{root : [ {"column1": "abc", "column2": "def", "column3": "dghi", "column4": "jkl", "column5": "mno"}, {"column1": "pqr", "column2": "stu", "column3": "vwx", "column4": "", "column5": ""} ]}
我最近使用curl遇到了这个问题,这是一个简单的错字。我不是使用内联json,而是使用文件。我忘了在文件名前加上@符号。
curl -XPUT -H'Content-Type:application/json' localhost:9200/twitter -d@mappings.json