0
0
Elasticsearchquery~30 mins

Percolate queries (reverse search) in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Percolate Queries (Reverse Search) with Elasticsearch
📖 Scenario: You work at a news agency. You want to save some search queries so that when new articles arrive, you can quickly find which saved queries match the new articles. This helps you notify readers about news they care about.
🎯 Goal: You will create a percolator index, add saved queries, add a new article, and then find which saved queries match the new article using Elasticsearch percolate queries.
📋 What You'll Learn
Create an Elasticsearch index with a percolator field called query
Index saved queries using the query field
Index a new document (article) to test against saved queries
Use a percolate query to find which saved queries match the new article
💡 Why This Matters
🌍 Real World
News agencies, alert systems, and recommendation engines use percolate queries to quickly find saved searches that match new incoming data.
💼 Career
Understanding percolate queries is useful for roles involving Elasticsearch, search engineering, and real-time alerting systems.
Progress0 / 4 steps
1
Create the percolator index with mapping
Create an Elasticsearch index called news_queries with a mapping that has a query field of type percolator and a content field of type text.
Elasticsearch
Need a hint?

Use the PUT method to create an index with a mapping. The query field must be of type percolator.

2
Index saved queries using the percolator field
Index two saved queries into the news_queries index. Use document IDs 1 and 2. The first query should match documents containing the word sports in content. The second query should match documents containing the word politics in content. Store these queries in the query field.
Elasticsearch
Need a hint?

Use PUT /news_queries/_doc/1 and PUT /news_queries/_doc/2 to index the saved queries. The queries go inside the query field.

3
Index a new article document
Index a new document into an index called news_articles with ID 1. The document should have a content field with the text: Latest sports update from the championship.
Elasticsearch
Need a hint?

Create a new index news_articles and add a document with the given content.

4
Use percolate query to find matching saved queries
Run a search on the news_queries index using a percolate query. The query should check which saved queries match the document with content: Latest sports update from the championship. Print the IDs of matching saved queries.
Elasticsearch
Need a hint?

Use a percolate query in the search body on news_queries to find matching saved queries.