liveBook · Manning

Wildcard query

As explained in Elasticsearch in Action, Second Edition

An Elasticsearch wildcard query is a term-level query that matches indexed terms using wildcard characters.

Use an Elasticsearch wildcard query when a search term contains unknown characters, such as movie titles beginning with “god” or words resembling “godfather.” It is a term-level query: matching is binary, and the value is not analyzed at query time. section 9.7 section 9.10

Table 9.2 Types of wildcards (view table figure)

Character

Description

* (asterisk)

Searches for zero or more characters

? (question mark)

Searches for a single character

Use * for zero or more characters and ? for exactly one character. section 9.7

Find titles beginning with “god”

GET movies/_search { "query": { "wildcard": { "title": { "value": "god*" } } } } The god* pattern matches a word beginning with god, including titles such as The Godfather, The Godfather II, and City of God. A pattern such as g*d can match words containing any number of characters between g and d. section 9.7

Apply wildcard queries with these field and matching considerations:

  • Use lowercase values on analyzed text fields when the index analyzer lowercased the original terms; wildcard queries do not analyze their input. section 9.7
  • Query a keyword subfield such as title.original when matching the complete stored value; “The God*” differs from “God*” because keyword values preserve the indexed text. section 9.7
  • Map fields as wildcard data types when the field is intended for wildcard and regular-expression searches; keyword-family fields can improve search performance when used appropriately. section 4.5.2

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains * and ?, text-versus-keyword behavior, highlighting, and wildcard mappings without detailing query execution internals.
Examples
Uses movie-title patterns such as god*, g*d, and go?ather, plus an error-description search using *obj*.
What it assumes
Assumes indexed fields and distinguishes analyzed text values from exact keyword values before constructing the query.
What you can do after
Apply it via the Elasticsearch REST API to retrieve terms matching zero, one, or multiple wildcard characters.
How it connects
Connects wildcard queries with term-level search, text analysis, keyword fields, highlighting, and wildcard data types.

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.