英文:
Elasticsearch query to return documents with given ids
问题
所有在Elasticsearch索引中的文档都有一个id
字段。
我有一个id
数组,我想获取具有在这个数组中的id
的文档。这个任务的Elasticsearch查询是什么?
英文:
All the documents in the elasticsearch index have an id
field.
I have an array of id
s and I want to fetch documents with id
s in this array. What is the elasticsearch query for this task?
答案1
得分: 1
让我们假设您有一个类似于["36088175", "36088176"]
的数组中的ID。
查询将是:
{
"query": {
"terms": {
"_id": ["36088175", "36088176"]
}
}
}
有关更多细节,请查看术语查询 - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
英文:
let's say you have ids in array like ["36088175", "36088176"]
The query will be
{
"query" : {
"terms" : {
"_id" : ["36088175", "36088176"]
}
}
}
see terms query for more details - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
答案2
得分: 1
The most efficient query for this is an mget
:
示例:
GET myindex/_mget
{
"docs" : [
{
"_id" : "fIjOTW8BkTKnAOE5HVit"
},
{
"_id" : "fojOTW8BkTKnAOE5UliD"
}
]
}
更多信息请参阅Elasticsearch文档
英文:
Saga, the most efficient query for this is an mget
:
Example :
GET myindex/_mget
{
"docs" : [
{
"_id" : "fIjOTW8BkTKnAOE5HVit"
},
{
"_id" : "fojOTW8BkTKnAOE5UliD"
}
]
}
More information on Elasticsearch's documentation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论