Get APIedit
The get API allows to get a typed JSON document from the index based on its id. The following example gets a JSON document from an index called twitter, under a type called tweet, with id valued 1:
GetResponse response = client.prepareGet("twitter", "tweet", "1").get();
For more information on the get operation, check out the REST get docs.
Multi Get APIedit
The multi get API allows to get a list of documents based on their index, type and id:
MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
.add("twitter", "tweet", "1")
.add("twitter", "tweet", "2", "3", "4")
.add("another", "type", "foo")
.get();
for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
GetResponse response = itemResponse.getResponse();
if (response.isExists()) {
String json = response.getSourceAsString();
}
}
get by a single id | |
or by a list of ids for the same index / type | |
you can also get from another index | |
iterate over the result set | |
you can check if the document exists | |
access to the |
For more information on the multi get operation, check out the REST multi get docs.
本文介绍了Elasticsearch中的Get API和Multi Get API使用方法。Get API可以根据ID从指定索引中获取JSON文档,而Multi Get API则允许一次性获取多个文档,支持按索引、类型和ID批量检索。
3万+

被折叠的 条评论
为什么被折叠?



