AI Hints
Home›Elasticsearch Tutorial›Multi Get and By Query
Elasticsearch · Lesson 19 of 120

Multi Get

Many IDs, one request.

⏱ 2 min read▶ Video at 17:28🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

A shopping cart holds three products. You know their IDs, and you need all three. Instead of three GET requests, use multi get.

  • A cart of three
  • Known IDs
  • One request

Get three products

Send a list of IDs to_m get. The source parameter picks only the name and price. Run it. We get three documents back, and the made up ID nine nine nine says found false.

Dev Tools Consoletext
GET products/_mget?_source=name,price&filter_path=docs._id,docs.found,docs._source
{
  "ids": ["1", "14", "999"]
}
Output
{
  "docs": [
    {
      "_id": "1",
      "found": true,
      "_source": {
        "name": "Basecamp 2-Person Tent",
        "price": 237.99
      }
    },
    {
      "_id": "14",
      "found": true,
      "_source": {
        "name": "Daypack 22L Hiking Backpack",
        "price": 173.99
      }
    },
    {"_id": "999", "found": false}
  ]
}
Also uses _load
products

Use multi get when you already know the IDs, like items in a cart. It's real-time, so it sees documents before a refresh. Use search when you're looking for documents by their content.

keyvalue
Know the IDs_mget
Real-timeno refresh needed
Looking by content_search
Cart, wishlistperfect for _mget

Summary

Underscore m get fetches many documents by ID in one request. Next, changing or deleting every document that matches a query.

Key takeaways
  • _mget
  • ids list
  • found per doc
Next up: Update and Delete by Query — change many at once