Bird
Raised Fist0

You have stored queries with different filters on a tags array field. How can you use a percolate query to find all queries matching a document with tags ["news", "sports"]?

hard🚀 Application Q9 of Q15
Elasticsearch - Advanced Patterns

You have stored queries with different filters on a tags array field. How can you use a percolate query to find all queries matching a document with tags ["news", "sports"]?

A{ "percolate": { "field": "query", "document": { "tags": ["news", "sports"] } } }
B{ "query": { "percolate": { "field": "query", "document": { "tags": "news sports" } } } }
C{ "query": { "match": { "tags": ["news", "sports"] } } }
D{ "query": { "percolate": { "field": "query", "document": { "tags": ["news", "sports"] } } } }
Step-by-Step Solution
Solution:
  1. Step 1: Provide the document with tags as an array

    The document must include the 'tags' field as an array matching stored queries.
  2. Step 2: Use the percolate query inside the 'query' key

    The percolate query must be wrapped inside 'query' with correct 'field' and 'document'.
  3. Final Answer:

    { "query": { "percolate": { "field": "query", "document": { "tags": ["news", "sports"] } } } } -> Option D
  4. Quick Check:

    Percolate with array fields = Correct document format [OK]
Quick Trick: Pass arrays as arrays in document for percolate queries [OK]
Common Mistakes:
MISTAKES
  • Passing array as space-separated string
  • Omitting 'query' wrapper
  • Using 'match' query instead of percolate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes