AI Hints
Home›Elasticsearch Tutorial›Your First Searches
Elasticsearch · Lesson 22 of 120

Your First Search

The _search endpoint.

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

Now the fun part, searching. Every search goes to the_search endpoint of an index. The simplest search of all just matches every document.

  • _search endpoint
  • Send a query
  • Get hits

match_all

Match all matches every document. Size three asks for only three results. And filter path keeps just the product names. Run it. We get three products back, out of all forty nine.

Dev Tools Consoletext
GET products/_search?filter_path=hits.hits._source.name
{
  "query": { "match_all": {} },
  "size": 3
}
Output
{
  "hits": {
    "hits": [
      {"_source": {"name": "Basecamp 2-Person Tent"}},
      {"_source": {"name": "Basecamp 3-Person Tent"}},
      {"_source": {"name": "Basecamp 4-Person Tent"}}
    ]
  }
}
Also uses _load
products

A search request is a JSON body. Query says which documents match. Size says how many to return, ten by default. And from says how many to skip, for paging.

keyvalue
querywhich docs match
sizehow many, default 10
fromhow many to skip
_sourcewhich fields to return

Summary

GET index slash_search, with a query in the body, is how every search starts. Match all matches everything. Next, reading the response.

Key takeaways
  • _search
  • match_all
  • size
Next up: Reading the Response — took, hits and scores