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
