Bird
0
0

You want to search documents where the tags field contains either "red" or "blue". Which query is correct?

hard🚀 Application Q9 of 15
Elasticsearch - Basics and Architecture

You want to search documents where the tags field contains either "red" or "blue". Which query is correct?

A{ "query": { "term": { "tags": ["red", "blue"] } } }
B{ "query": { "terms": { "tags": ["red", "blue"] } } }
C{ "query": { "match": { "tags": "red blue" } } }
D{ "query": { "bool": { "must": [ { "term": { "tags": "red" } }, { "term": { "tags": "blue" } } ] } } }
Step-by-Step Solution
Solution:
  1. Step 1: Identify query for multiple exact values

    The terms query accepts an array of values and matches any document containing any of those values.
  2. Step 2: Compare with other options

    term does not accept arrays, match treats text differently, and bool must requires all terms, not either/or.
  3. Final Answer:

    terms query with array of values -> Option B
  4. Quick Check:

    Use terms for multiple exact values [OK]
Quick Trick: terms query matches any value in array [OK]
Common Mistakes:
MISTAKES
  • Using term with arrays
  • Using bool must for OR logic
  • Using match for exact tags

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes