Bird
0
0

You want to rank documents by relevance but also exclude those with "draft" status. Which query correctly ranks by relevance and filters out drafts?

hard🚀 Application Q15 of 15
Elasticsearch - Search Results and Scoring
You want to rank documents by relevance but also exclude those with "draft" status. Which query correctly ranks by relevance and filters out drafts?
{
  "query": {
    "bool": {
      "must": {
        "match": { "text": "Elasticsearch" }
      },
      "filter": {
        "term": { "status": "draft" }
      }
    }
  }
}
AUse "filter" for both match and filtering drafts
BUse "filter" for match and "must" for filtering drafts
CUse "should" for both match and filtering drafts
DUse "must" for match and "must_not" for filtering drafts
Step-by-Step Solution
Solution:
  1. Step 1: Understand must and filter roles

    must runs scoring queries; filter filters without scoring; must_not excludes documents.
  2. Step 2: Apply exclusion for drafts

    To exclude drafts, use must_not with a term filter on status "draft"; keep must for scoring match query.
  3. Final Answer:

    Use "must" for match and "must_not" for filtering drafts -> Option D
  4. Quick Check:

    Must scores, must_not excludes [OK]
Quick Trick: Use must for scoring, must_not to exclude unwanted docs [OK]
Common Mistakes:
MISTAKES
  • Using filter to exclude documents (doesn't exclude)
  • Using should which affects scoring differently
  • Filtering match query disables scoring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes