如何在 elasticsearch 的 POST 请求正文中指定要索引的 2 个或更多文档?

尼哈

我是弹性搜索的新手。我创建了一个名为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!

Tarek Essam

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何提取具有 2 个或更多嵌套对象的文档?

来自分类Dev

如何在TensorFlow回归中指定2个或更多输出标签

来自分类Dev

如何在Solr的多值字段中搜索具有2个或更多条目的文档?

来自分类Dev

如何在POST请求中发送两个正文?

来自分类Dev

如何在NEST2中更新Elasticsearch文档

来自分类Dev

如何在NEST2中更新Elasticsearch文档

来自分类Dev

如何在elasticsearch中将一个索引文档复制到另一索引?

来自分类Dev

如何在Elasticsearch索引中删除多个ID文档

来自分类Dev

如何在 Elasticsearch 中减少请求正文

来自分类Dev

如何在ElasticSearch中``联接''两个索引

来自分类Dev

如何在Android中使用Volley在POST请求的正文中传递数组

来自分类Dev

如何在WebApp2中解析Angular POST请求

来自分类Dev

如何在WebApp2中解析Angular POST请求

来自分类Dev

如何在 Retrofit 2 (Android) 中发送 POST 请求

来自分类Dev

如何在Ruby 2中为Net :: HTTP :: Post.new请求指定读取超时

来自分类Dev

如何在Postman Collection中指定JSON请求正文示例

来自分类Dev

如何在Elasticsearch中管理文档的“版本”?

来自分类Dev

如何在JMeter的POST正文中转义\ r \ n

来自分类Dev

Elasticsearch:在一个请求中获取多个指定文档?

来自分类Dev

如何在“ for”中放入2个或更多“ id”?

来自分类Dev

如何增加 elasticsearch 文档限制/索引计数?

来自分类Dev

如何在Elasticsearch中指定default-mapping.json

来自分类Dev

Swagger文档-如何在JSON请求正文中仅获取用逗号分隔的值?

来自分类Dev

我们如何从 elasticsearch 索引中获取最后一个文档?

来自分类Dev

如何在Slim中访问POST请求的JSON请求正文?

来自分类Dev

如何在Golang的Elasticsearch文档(已索引)中搜索字符串?

来自分类Dev

如何在索引时防止Elasticsearch将日期类型文档作为UTC时区插入

来自分类Dev

Rails的活动资源:如何在请求正文中而不是查询字符串中发送post参数?

来自分类Dev

RESTFul:应该如何指定POST请求正文格式?

Related 相关文章

  1. 1

    如何提取具有 2 个或更多嵌套对象的文档?

  2. 2

    如何在TensorFlow回归中指定2个或更多输出标签

  3. 3

    如何在Solr的多值字段中搜索具有2个或更多条目的文档?

  4. 4

    如何在POST请求中发送两个正文?

  5. 5

    如何在NEST2中更新Elasticsearch文档

  6. 6

    如何在NEST2中更新Elasticsearch文档

  7. 7

    如何在elasticsearch中将一个索引文档复制到另一索引?

  8. 8

    如何在Elasticsearch索引中删除多个ID文档

  9. 9

    如何在 Elasticsearch 中减少请求正文

  10. 10

    如何在ElasticSearch中``联接''两个索引

  11. 11

    如何在Android中使用Volley在POST请求的正文中传递数组

  12. 12

    如何在WebApp2中解析Angular POST请求

  13. 13

    如何在WebApp2中解析Angular POST请求

  14. 14

    如何在 Retrofit 2 (Android) 中发送 POST 请求

  15. 15

    如何在Ruby 2中为Net :: HTTP :: Post.new请求指定读取超时

  16. 16

    如何在Postman Collection中指定JSON请求正文示例

  17. 17

    如何在Elasticsearch中管理文档的“版本”?

  18. 18

    如何在JMeter的POST正文中转义\ r \ n

  19. 19

    Elasticsearch:在一个请求中获取多个指定文档?

  20. 20

    如何在“ for”中放入2个或更多“ id”?

  21. 21

    如何增加 elasticsearch 文档限制/索引计数?

  22. 22

    如何在Elasticsearch中指定default-mapping.json

  23. 23

    Swagger文档-如何在JSON请求正文中仅获取用逗号分隔的值?

  24. 24

    我们如何从 elasticsearch 索引中获取最后一个文档?

  25. 25

    如何在Slim中访问POST请求的JSON请求正文?

  26. 26

    如何在Golang的Elasticsearch文档(已索引)中搜索字符串?

  27. 27

    如何在索引时防止Elasticsearch将日期类型文档作为UTC时区插入

  28. 28

    Rails的活动资源:如何在请求正文中而不是查询字符串中发送post参数?

  29. 29

    RESTFul:应该如何指定POST请求正文格式?

热门标签

归档