liveBook · Manning

Ids query

As explained in Elasticsearch in Action, Second Edition

An ids query is an Elasticsearch query that selects documents whose identifiers match a specified set of IDs.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines the JSON structure and endpoint, then stops short of deeper search-API treatment.
Examples
Uses books and movie indexes with arrays of numeric document IDs, including a multiple-index search URL.
What it assumes
Assumes familiarity with Elasticsearch indexes and document IDs while introducing Query DSL structure and search-based retrieval.
What you can do after
Apply it via Elasticsearch's _search API to retrieve documents matching a supplied list of IDs.
How it connects
Connects document retrieval, search API, Query DSL, terms query, and metadata fields.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.