[英]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.