An ids query retrieves multiple Elasticsearch documents when their document identifiers are already known. It uses the search API rather than an individual document endpoint, making it convenient for fetching a selected set at once. section 2.2.2 section 5.2.3
Fetch selected books
GET books/_search { "query": { "ids": { "values": [1, 2, 3] } } } The values array supplies the document IDs to match. The response returns the matching hits with metadata and, by default, the original source document. section 2.2.2
Use the query with these operational considerations:
- Target several indexes by placing their names in the search URL, such as classic_movies,international_movies/_search. section 5.2.3
- Suppress unnecessary source data with "_source": false when the client needs matching documents without their original fields. section 2.2.2
- Use a terms query on _id as an alternative for matching a set of document IDs; _id is metadata rather than a mapped schema field. section 9.4
