Bird
0
0

You want to sort search results first by category alphabetically ascending, then by price descending. Which is the correct sort clause?

hard🚀 Application Q15 of 15
Elasticsearch - Search Results and Scoring
You want to sort search results first by category alphabetically ascending, then by price descending. Which is the correct sort clause?
A"sort": {"category": "asc", "price": "desc"}
B"sort": [{"price": "desc"}, {"category": "asc"}]
C"sort": [{"category": "asc"}, {"price": "desc"}]
D"sort": [{"category": "desc"}, {"price": "asc"}]
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-level sorting order

    Sorting applies fields in order: first field sorts primary, second field breaks ties.
  2. Step 2: Match required order

    First by category ascending, then by price descending means category asc first, price desc second.
  3. Step 3: Validate syntax

    Sort must be an array of objects with field and order pairs.
  4. Final Answer:

    "sort": [{"category": "asc"}, {"price": "desc"}] -> Option C
  5. Quick Check:

    Primary asc category, secondary desc price [OK]
Quick Trick: List sort fields in order inside array [OK]
Common Mistakes:
MISTAKES
  • Reversing sort order of fields
  • Using object instead of array for multiple fields
  • Mixing ascending and descending incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes