ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # 简介 为了能更快的同时检索多个文档 mget API参数是一个docs数组,数组的每个节点定义一个文档的`_index,_type,_id`元数据 例子 ![](https://box.kancloud.cn/41839d4c12dffeb6fba4db164847ca88_304x474.png) 我们先创建出一些数据,然后我们看下 ~~~ GET /library/books/1 GET /library/books/2 GET /library/books/3 GET /shakespeare/line/1 GET /shakespeare/line/2 GET /shakespeare/line/3 ~~~ # 一起获取下 ~~~ # 数组[] GET /_mget { "docs": [ { "_index": "library", "_type": "books", "_id": 1 }, { "_index": "library", "_type": "books", "_id": 2 }, { "_index": "library", "_type": "books", "_id": 3 }, { "_index": "shakespeare", "_type": "line", "_id": 1 }, { "_index": "shakespeare", "_type": "line", "_id": 2 }, { "_index": "shakespeare", "_type": "line", "_id": 3 } ] } ~~~ # 可以指定你想获取的字段 ~~~ # 也可以指定_source字段,获取你想要的 GET /_mget { "docs": [ { "_index": "library", "_type": "books", "_id": 1, "_source": "title" }, { "_index": "library", "_type": "books", "_id": 2, "_source": "name" }, { "_index": "library", "_type": "books", "_id": 3, "_source": "price" }, { "_index": "shakespeare", "_type": "line", "_id": 1, "_source": "name" }, { "_index": "shakespeare", "_type": "line", "_id": 2, "_source": ["name","password"] }, { "_index": "shakespeare", "_type": "line", "_id": 3, "_source": "password" } ] } ~~~ # 获取相同index相同type下不同ID的文档 ~~~ GET /library/books/_mget { "docs": [ {"_id": 1}, {"type":"books","_id":3} ] } ~~~ # 可以这样简便的写 ~~~ GET /library/books/_mget { "ids": ["1", "3"] } ~~~