以下cURL命令正在运行:
curl -XPOST http://localhost:9200/test/test -d '{"name":"John", "age":31}' -H 'Content-Type: application/json'
但是,当我执行以下命令时:
curl -XPOST http://localhost:9200/test/test -d '/mnt/c/path/to/filename/test.json' -H 'Content-Type: application/json'
我收到以下错误:
{"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}
这有点奇怪,因为此“test.json”的内容与第一个命令中的内容完全相同。即:“{{name”:“John”,“age”:31}”的压缩版本。
最佳答案
发送文件时,您需要使用--data-binary
标志而不是-d
:
curl -XPOST http://localhost:9200/test/test --data-binary @'/mnt/c/path/to/filename/test.json' -H 'Content-Type: application/json'
关于json - Elasticsearch API从路径插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52755780/