0
0
Elasticsearchquery~3 mins

Why Percolate queries (reverse search) in Elasticsearch? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could instantly know which saved searches match any new piece of data without running each search one by one?

The Scenario

Imagine you have hundreds of saved search rules and you want to find out which rules match a new document you just received. Doing this by checking each rule one by one manually is like searching for a needle in a haystack.

The Problem

Manually comparing a new document against many saved queries is slow and error-prone. It wastes time and computing power because you have to run each query separately, and it's easy to miss matches or make mistakes.

The Solution

Percolate queries let you reverse the process: instead of running many queries on new data, you register your queries once, then send new documents to find which queries match instantly. This saves time and makes searching efficient and reliable.

Before vs After
Before
for query in saved_queries:
    if query.matches(new_document):
        print('Match found')
After
POST /my_index/_percolate
{
  "doc": { "field": "value" }
}
What It Enables

It enables instant matching of new documents against many saved queries, making real-time alerting and filtering possible.

Real Life Example

A news website wants to notify users when articles match their interests. Using percolate queries, the site quickly finds which user queries match each new article and sends alerts immediately.

Key Takeaways

Manual matching of documents to queries is slow and inefficient.

Percolate queries reverse the search process for fast matching.

This technique supports real-time notifications and filtering.