欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Multi GET API介绍

发布时间:2025/3/15 编程问答 23 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Multi GET API介绍 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

#先添加几个文档

PUT /lib/user/1 {"first_name":"Jane","last_name":"Smith","age":36,"about":"I like to collect rock albums","interests":["music"] }PUT /lib/user/2 {"first_name":"Jane","last_name":"tom","age":38,"about":"I like to collect rock albums","interests":["music"] }

 

 获取

#批量获取文档 Multi GET API GET /_mget {"docs":[{"_index":"lib","_type":"user","_id":1},{"_index":"lib","_type":"user","_id":2},{"_index":"lib","_type":"user","_id":3}]}

返回信息:

{"docs" : [{"_index" : "lib","_type" : "user","_id" : "1","_version" : 1,"_seq_no" : 7,"_primary_term" : 1,"found" : true,"_source" : {"first_name" : "Jane","last_name" : "Smith","age" : 36,"about" : "I like to collect rock albums","interests" : ["music"]}},{"_index" : "lib","_type" : "user","_id" : "2","_version" : 1,"_seq_no" : 3,"_primary_term" : 1,"found" : true,"_source" : {"first_name" : "Jane","last_name" : "tom","age" : 38,"about" : "I like to collect rock albums","interests" : ["music"]}},{"_index" : "lib","_type" : "user","_id" : "3","found" : false}] }

文档id=1和文档id=2返回true  文档id=3的返回false 因为文档3没有添加

获取文档指定的字段

#获取指定字段 GET /_mget {"docs":[{"_index":"lib","_type":"user","_id":1,"_source": "interests"},{"_index":"lib","_type":"user","_id":2,"_source":["interests","age"]}]}

获取结果:

{"docs" : [{"_index" : "lib","_type" : "user","_id" : "1","_version" : 1,"_seq_no" : 7,"_primary_term" : 1,"found" : true,"_source" : {"interests" : ["music"]}},{"_index" : "lib","_type" : "user","_id" : "2","_version" : 1,"_seq_no" : 3,"_primary_term" : 1,"found" : true,"_source" : {"interests" : ["music"],"age" : 38}}] }

 

 

 

 

总结

以上是生活随笔为你收集整理的Multi GET API介绍的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。