我是弹性搜索的新手。我创建了一个名为comforts的索引,并尝试在Postman 工具http://localhost:9200/amenities/test/_bulk 中执行POST 请求。
在这里,内容类型设置为 application/json 以及它在执行请求时给出的错误。
在这里,它显示了 JSON 中的语法错误。
我无法理解如何索引多个 JSON 对象(文档)。当我只指定一个文档时它运行良好,但当我指定两个或更多时 JSON 变得无效。
我尝试了以下解决方案:
{"index":{}} {"type": "Kitchen","location": {"x": 9881.034723869176,"y": -12942.49413158995},"icon": "utensils","category": "Amenities"} {"index":{}} {"type": "Rubbish Bin","location": {"x": 9170.444649524274,"y": -12855.890257805067},"icon": "trash","category": "Amenities"}
{"index" : { "_index" : "amenities", "_type" : "test"}} {"type": "Kitchen","location": {"x": 9881.034723869176,"y": -12942.49413158995},"icon": "utensils","category": "Amenities"} {"index" : { "_index" : "amenities", "_type" : "test"}} {"type": "Rubbish Bin","location": {"x": 9170.444649524274,"y": -12855.890257805067},"icon": "trash","category": "Amenities"}
which still gives a syntax error.
What am I missing? Thanks!
You can put your docs in a json file in the following format (testData.json):
{"index": {"_index": "animals", "_type": "_doc", "_id": 1}}
{"name": "dog"}
{"index": {"_index": "animals", "_type": "_doc", "_id": 2}}
{"name": "cat"}
and use curl like this:
curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@testData.json";
或者,如果您想在没有 json 文件的情况下使用 curl:
curl -X POST "localhost:9200/_bulk" -H 'Content-Type: application/json' -d'
{ "index" : { "_index" : "test", "_type" : "_doc", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "_doc", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }'
或者你可以使用 kibana,这更容易。检查文档_bulk
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句