liveBook · Manning

Wildcard

As explained in Elasticsearch in Action, Second Edition

A wildcard is a pattern symbol representing one or more variable characters when selecting index names or matching terms.

A wildcard is a pattern operator that stands for variable characters. In Elasticsearch, it selects groups of index names or matches terms within indexed fields. section 6.3.1 section 9.7

Use two wildcard characters for different matching behavior:

  • * matches zero or more characters, so god* finds terms beginning with god and g*d can match Good or God. section 9.7
  • ? matches exactly one character, so go?ather matches a word with one character in that position; multiple question marks can be combined. section 9.7

Search movie titles with a wildcard

GET movies/_search { "query": { "wildcard": { "title": { "value": "god*" } } } } The query can return The Godfather, The Godfather II, and City of God. Because wildcard queries are term-level queries, they are not analyzed; the lowercase value matches the lowercase terms produced by the standard analyzer. On a keyword field, use the complete stored form, such as "The God*" on title.original. section 9.7

Select index configurations by pattern

GET ca* This request retrieves configurations for every index beginning with ca. Multiple patterns can be comma-separated, as in GET mov*,stu*, without spaces after commas. section 6.3.1

Listing 9.15 Wildcard search in action
GET movies/_search
{
  "query": {
    "wildcard": {         #1
      "title": {
        "value": "god*"   #2
      }
    }
  }
}

Inspect the complete REST request for a wildcard search against the movies index. section 9.7

Wildcards can make live searches expensive. Search behavior also depends on field mapping: analyzed text fields require the matching analyzed term, whereas keyword fields preserve the original value. Elasticsearch also provides wildcard as a keyword-family data type for suitable structured or pattern-oriented fields. section 9.7 section 4.4

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains both wildcard operators, analyzed versus keyword fields, and expensive-query concerns without detailing execution internals.
Examples
Uses ca*, mov*, stu*, god*, g*d, and go?ather for index selection and movie-title matching.
What it assumes
Assumes basic Elasticsearch indexes, mappings, fields, and REST requests while explaining wildcard syntax from zero.
What you can do after
Apply wildcard patterns through Elasticsearch REST requests while accounting for field analysis and query cost.
How it connects
Connects wildcard queries with term-level queries, keyword fields, text analysis, prefix queries, and highlighting.

Also explained in

Compare how 8 books explain wildcard →

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.