liveBook · Manning

Match query

As explained in Elasticsearch in Action, Second Edition

A match query is an Elasticsearch query clause that analyzes supplied text and matches documents containing corresponding terms.

A match query searches unstructured text fields for supplied words and returns matching documents with relevance scores. Use it when a bookstore reader searches a title or author rather than an exact structured value. section 10.0 section 10.5

Listing 10.4 Searching for Java books
GET books/_search
{
  "query": {
    "match": {          #1
      "title": "Java"   #2
    }
  }
}

Search for Java in the title field by placing a match clause inside the _search request's query object. section 10.5.2 section 10.5.1

The query value can contain one or more words in any case. Match queries analyze text with the analyzer used at indexing unless a different search analyzer is explicitly configured; with the standard analyzer, JAVA, java, and jaVA produce the same result. section 10.5.1 section 10.5.3

Extend a match query when the search requirement changes:

  • Add fuzziness to tolerate character mistakes, such as matching Komputer with Computer at fuzziness 1. section 2.3.8
  • Place it in a bool must clause with match_phrase, range, term, or other leaf queries to require several conditions. section 2.5.2 section 11.3.3
  • Expect query context to score matches; placing it in a bool filter removes relevance scoring when only match status matters. section 8.4.2

Author search

To find books by Joshua Bloch, match the author field against Joshua. Elasticsearch analyzes the request, searches its inverted indexes, retrieves matching documents, and returns the result. A shortened value such as josh needs a prefix query instead; prefix queries are term-level and require lowercase input. section 2.3.1

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains request formats, analyzer processing, scoring, fuzziness, and bool composition without detailing relevance-algorithm internals.
Examples
Demonstrates author, Java-title, Godfather-title, misspelled Komputer, and price-bounded TV searches.
What you can do after
Apply it via the _search API to search text, tolerate misspellings, and combine criteria in bool queries.
How it connects
Connects match queries to full-text search, analyzers, inverted indexes, fuzziness, bool queries, filters, and range queries.

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.