Elasticsearch查询以返回具有指定ID的文档。

huangapple go评论75阅读模式
英文:

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 ids and I want to fetch documents with ids 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

huangapple
  • 本文由 发表于 2020年1月7日 02:23:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/59617066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定