liveBook · Manning

Percolator field type

As explained in Elasticsearch in Action, Second Edition

The percolator field type stores and indexes Elasticsearch queries so they can later be matched against documents.

A percolator field type stores search queries so Elasticsearch can later test incoming documents against them. This reverses ordinary search: instead of running a query against documents, it finds queries that match a document. A bookstore can use it to notify a customer when an unavailable Python book returns to inventory. section 12.9.4

A basic percolator workflow is:

  • Create an index with a query field mapped as type percolator. section 12.9.4
  • Store a query such as a match query for name: Python. section 12.9.4
  • When the matching book is indexed, submit that document to a percolate query and retrieve matching stored queries. section 12.9.4

Book restocking notification

Store {"query":{"match":{"name":"Python"}}} in tech_books_percolator. After indexing {"name":"Python in Action","tags":["Python","Software Programming"]}, search the percolator index with {"percolate":{"field":"query","document":{...}}}. The result identifies the stored query that now matches. section 12.9.4

Listing 12.29 Creating a percolator index
PUT tech_books_percolator
{
  "mappings": {
    "properties": {
      "query": {                #1
        "type": "percolator"    #2
      },
      "name": {                 #3
        "type": "text"
      },
      "tags": {                 #4
        "type": "text"
      }
    }
  }
}

Inspect the mapping that defines the percolator query field alongside the document fields used by stored queries. section 12.9.4

Listing 12.32 Searching for queries in the percolator index
GET tech_books_percolator/_search
{
  "query": {
    "percolate": {          #1
      "field": "query",     #2
      "document": {         #3
        "name":"Python in Action",
        "tags":["Python","Software Programming"]
      }
    }
  }
}

Inspect the percolate search that supplies a document and returns matching stored queries. section 12.9.4

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains index mapping, query storage, document indexing, and reverse matching without detailing internal execution.
Examples
Uses technical books, a missing Python title, a stored name query, and a newly indexed inventory document.
What it assumes
Assumes basic indexing and match-query usage while introducing the reversed query-against-document model.
What you can do after
Apply via Elasticsearch to find stored queries matching newly indexed documents.
How it connects
Connects percolate queries with match queries, index mappings, document indexing, and search-result notifications.

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.