[英]How to find by ID & IDs in ElasticSearch and ElasticSearch Javascript client
我试图在弹性搜索中通过 ID 查找最常见的查找用法。
直接使用 Elasticsearch API通过 ID 查找:
GET /myindex/mytype/1
使用用于 ElasticSearch 的 JavaScript 客户端按 ID 查找:
let body = {};
client.get({
index: 'myindex',
type: 'mytype',
id: 1
}, (error, response) => {
body = response.body;
// ...
});
// TODO: Validation of return object.
return body;
使用 Elasticsearch API 直接通过多个 ID 查找:
GET /_search
{
"query": {
"ids" : {
"type" : "my_type",
"values" : ["1", "4", "100"]
}
}
}
使用 ElasticSearch 的 JavaScript 客户端通过多个 ID 查找:
client.search({
index: 'myindex',
body: {
query: {
ids: {
type: "my_type",
values: ["1", "4", "100"]
}
}
},
}, (error, response) => {
// handle response here
});
您也可以使用mget进行此类查询,例如:
const getDocsByIds = (documentIds) => ({
index,
type,
body: {
ids: documentIds,
},
});
return elasticsearchClient.mget(getDocsByIds);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.