Thuta Learning
BasicData & Databasesbeginner

Search Basics — `_search`, `match`, and the Query DSL

What you'll walk away with

  • Explain the core ideas behind Search Basics — `_search`, `match`, and the Query DSL
  • Run the sample Elasticsearch query or code and verify its output
  • Apply the technique correctly to the Tutorial Platform and production scenarios

Build the mental model

All of Elasticsearch's search functionality goes through a single `_search` endpoint, where you write a JSON-based query language called the Query DSL (Domain Specific Language) in the request body. `match` is the most commonly used query type for full-text search — it tokenizes the search term through an analyzer (lowercasing, splitting words) and compares those tokens against the inverted index, so a search for "Redis Cache" can match a document containing just "redis" or just "cache" (OR logic by default). This differs sharply from a `term` query, which does exact, un-analyzed matching — `term` skips the analyzer and compares the raw value, so using it on a text field can silently miss many relevant results. The response's `hits.hits` array lists matching documents, each carrying a `_score` relevance score — a higher score means a closer match, and results are sorted by score, highest first, by default. Think of it like a Google search box: you type in keywords, and the engine ranks each document by how closely it matches before showing results.

Connect it to a real scenario

When a user types "redis cache" into the Tutorial Platform's search box, the frontend sends `GET /tutorials/_search` with a `match` query against the `title` field — using `term` instead would require an exact string match (spaces and capitalization included), badly hurting the experience. Render each search result card from `hits.hits[].source`'s tutorial title and summary, keeping them sorted by `_score` so the most relevant results appear first, matching what the user actually intended.

Try the working example

http
GET /tutorials/_search
{
  "query": {
    "match": {
      "title": "redis cache"
    }
  }
}
You should see
You get a `hits.hits` array of tutorial documents whose `title` field contains "redis" or "cache", sorted by `_score`.

5-minute try-it

Write a request that searches for "database" on the `tags` field using `match`, then give an example scenario where searching the same term with `term` would produce a different result.

One important caution

Using a `term` query on a `text` field expecting an exact match — because it skips the analyzer, the indexed tokens (lowercased, stemmed) may not match the query value's original casing, returning zero results.

Assuming a multi-word `match` query requires every word to be present (AND logic) when its default behavior is actually OR logic.

Elasticsearch Guide — Search Your DataElastic

Easy traps

  • Using a `term` query on a `text` field expecting an exact match — because it skips the analyzer, the indexed tokens (lowercased, stemmed) may not match the query value's original casing, returning zero results.
  • Assuming a multi-word `match` query requires every word to be present (AND logic) when its default behavior is actually OR logic.
  • Validate sample queries and requests on a local or test instance with recoverable data before applying them to production.

Exercise

Write a request that searches for "database" on the `tags` field using `match`, then give an example scenario where searching the same term with `term` would produce a different result.

You'll know it worked when: You get a `hits.hits` array of tutorial documents whose `title` field contains "redis" or "cache", sorted by `_score`.

Search Basics — `_search`, `match`, and the Query DSL | Thuta Learning