Bird
0
0

How can you sort Elasticsearch results by a nested field comments.date ascending, assuming comments is a nested type?

hard🚀 Application Q9 of 15
Elasticsearch - Search Results and Scoring
How can you sort Elasticsearch results by a nested field comments.date ascending, assuming comments is a nested type?
A"sort": [{"comments.date": {"order": "asc", "nested": {"path": "comments"}}}]
B"sort": [{"comments.date": {"order": "asc"}}]
C"sort": [{"comments": {"order": "asc", "path": "comments.date"}}]
D"sort": [{"comments.date": {"order": "asc", "nested_path": "comments"}}]
Step-by-Step Solution
Solution:
  1. Step 1: Recognize nested field sorting syntax

    Sorting on nested fields requires specifying the nested path inside a "nested" object.
  2. Step 2: Check each option

    "sort": [{"comments.date": {"order": "asc", "nested": {"path": "comments"}}}] correctly uses "nested": {"path": "comments"}. "sort": [{"comments.date": {"order": "asc"}}] misses nested path. "sort": [{"comments": {"order": "asc", "path": "comments.date"}}] uses wrong keys. "sort": [{"comments.date": {"order": "asc", "nested_path": "comments"}}] uses incorrect key "nested_path".
  3. Final Answer:

    "sort": [{"comments.date": {"order": "asc", "nested": {"path": "comments"}}}] -> Option A
  4. Quick Check:

    Nested sort requires nested path object [OK]
Quick Trick: Use nested path object to sort nested fields [OK]
Common Mistakes:
MISTAKES
  • Omitting nested path for nested fields
  • Using wrong keys like nested_path
  • Trying to sort nested object directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes