0
0
Elasticsearchquery~10 mins

Percolate queries (reverse search) in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Percolate queries (reverse search)
Index percolator queries
New document arrives
Percolate query runs
Match queries found
Return matching query IDs
Percolate queries let you register queries first, then check which queries match a new document.
Execution Sample
Elasticsearch
PUT /my-index
{
  "mappings": {
    "properties": {
      "query": { "type": "percolator" },
      "message": { "type": "text" }
    }
  }
}

PUT /my-index/_doc/1
{
  "query": { "match": { "message": "error" } }
}

GET /my-index/_search
{
  "query": {
    "percolate": {
      "field": "query",
      "document": {
        "message": "this is an error message"
      }
    }
  }
}
This code registers a percolator query matching 'error' in 'message', then searches which queries match a new document.
Execution Table
StepActionInput/ConditionResult/Output
1Create index with percolator fieldDefine 'query' as percolator typeIndex ready to store queries
2Index percolator queryQuery: match 'message' contains 'error'Query stored with ID 1
3New document arrivesDocument: message='this is an error message'Document ready for percolation
4Run percolate queryCheck which stored queries match documentQuery ID 1 matches document
5Return matching queriesMatches foundResponse includes query ID 1
6EndNo more queriesPercolate search complete
💡 All stored queries checked against the new document; matching queries returned.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Indexemptycreated with percolator fieldunchangedunchangedunchanged
Stored Queriesnone1 query stored (match 'error')unchangedunchangedunchanged
New Documentnonenonedocument with message='this is an error message'unchangedunchanged
Matching Queriesnonenonenonequery ID 1 foundquery ID 1 returned
Key Moments - 3 Insights
Why do we index queries instead of documents in percolate?
Because percolate reverses the usual search: it stores queries first, then checks which queries match new documents (see execution_table step 2 and 4).
What does the 'percolate' query field refer to?
It refers to the field of type 'percolator' where queries are stored, as shown in execution_table step 1 and 4.
Why does the new document not get indexed normally?
Because percolate queries check the document against stored queries without indexing it as a normal document (see execution_table step 3 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the new document prepared for percolation?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Check the 'Action' and 'Input/Condition' columns for document arrival.
According to variable_tracker, what is the state of 'Matching Queries' after Step 4?
A1 query stored
Bnone
Cquery ID 1 found
Ddocument with message
💡 Hint
Look at the 'Matching Queries' row under 'After Step 4' column.
If we add another percolator query matching 'warning', what changes in the execution_table?
AStep 3 will change the document content
BStep 2 will show 2 queries stored
CStep 4 will find 2 matches for the same document
DStep 5 will return no matches
💡 Hint
Adding queries affects stored queries count (see variable_tracker 'Stored Queries').
Concept Snapshot
Percolate queries let you store queries first.
When a new document arrives, Elasticsearch checks which stored queries match it.
Define a 'percolator' field in mapping to store queries.
Index queries as documents with 'query' field.
Use 'percolate' query to find matching queries for a document.
Useful for alerting or reverse search scenarios.
Full Transcript
Percolate queries in Elasticsearch reverse the usual search process. Instead of storing documents and searching with queries, you store queries first in a special 'percolator' field. When a new document arrives, Elasticsearch runs these stored queries against the document to find matches. This is useful for alerting or matching documents to predefined criteria. The process involves creating an index with a percolator field, indexing queries as documents, then running a percolate query with a new document to find which queries match. The execution table shows each step from index creation, query storage, document arrival, percolate query execution, to returning matching queries. Variable tracking shows how stored queries and matching queries change over time. Key moments clarify why queries are stored, what the percolate field means, and why documents are not indexed normally. The visual quiz tests understanding of steps and variable states. The snapshot summarizes the concept in simple lines.