Percolate queries help you find which stored queries match a new document. It is like searching backwards: instead of finding documents for a query, you find queries for a document.
Percolate queries (reverse search) in Elasticsearch
{
"query": {
"percolate": {
"field": "query_field",
"document": {
"field1": "value1",
"field2": "value2"
}
}
}
}The field is where your stored queries live in the index mapping.
The document is the new data you want to test against those queries.
{
"query": {
"percolate": {
"field": "query",
"document": {
"message": "Elasticsearch is cool"
}
}
}
}{
"query": {
"percolate": {
"field": "query",
"document": {
"user": "alice",
"action": "login"
}
}
}
}This program creates an index with a percolator field, stores a query that matches documents containing "error", then percolates a new document with a message containing "error" to find matching queries.
PUT /my-index
{
"mappings": {
"properties": {
"query": {
"type": "percolator"
},
"message": {
"type": "text"
}
}
}
}
# Index a stored query
PUT /my-index/_doc/1
{
"query": {
"match": {
"message": "error"
}
}
}
# Percolate a new document to find matching queries
GET /my-index/_search
{
"query": {
"percolate": {
"field": "query",
"document": {
"message": "There was an error in the system"
}
}
}
}Make sure your index mapping includes a percolator type field to store queries.
Percolate queries are useful for alerting and matching new data against saved conditions.
Stored queries must be indexed before you can percolate documents against them.
Percolate queries let you find stored queries that match a new document.
You need a special percolator field in your index mapping to store queries.
Use percolate queries to build alerting and reverse search features.