Jordi
Jordi

Reputation: 23277

Get several documents by alternative ID in ElasticSearch

My documents have an alternative Id fields. I need to get them using it.

So, I know I'm able to use a multiget operation, however, this one needs I provide the ElsticSearch document id.

I'm actually trying something like this:

curl -XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' -d '{
  "query":{
     "filtered":{
        "filter":{
           "term":{
              "resources.source.sourceId.batch":"3fcb8905-a307-11e5-88de-382c4ab9e433"
           }
        }
     }
  }
}'

How could I request a query in order for ElasticSearch to provide every document that has resources.source.sourceId.batch eq to [id1, or id2, or ...]

Upvotes: 0

Views: 77

Answers (1)

Mateusz Dymczyk
Mateusz Dymczyk

Reputation: 15141

Instead of term you can use terms and pass an array of values you want to fetch.

curl -XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' -d '{
  "query":{
    "filtered":{
      "filter":{
        "terms":{
          "resources.source.sourceId.batch": ["id1", "id2", "id3"]
        }
      }
    }
  }
}'

Upvotes: 1

Related Questions