Bird
Raised Fist0

Which of the following JSON snippets correctly demonstrates how to implement search_after for paginating results sorted by timestamp in ascending order?

easy📝 Syntax Q3 of Q15
Elasticsearch - Advanced Patterns
Which of the following JSON snippets correctly demonstrates how to implement search_after for paginating results sorted by timestamp in ascending order?
A{ "size": 10, "search_after": [1627891234567], "sort": [{"timestamp": "asc"}] }
B{ "size": 10, "sort": [{"timestamp": "asc"}], "search_after": [1627891234567] }
C{ "size": 10, "sort": [{"timestamp": "desc"}], "search_after": ["1627891234567"] }
D{ "size": 10, "sort": [{"timestamp": "asc"}], "search_after": "1627891234567" }
Step-by-Step Solution
Solution:
  1. Step 1: Include sort clause

    The search_after parameter requires a sort clause to define the order of results.
  2. Step 2: Use an array for search_after values

    The value of search_after must be an array matching the sort fields' values from the last document.
  3. Step 3: Match sort order and data types

    The sort order must be ascending as specified, and the search_after value should be a number, not a string.
  4. Final Answer:

    { "size": 10, "sort": [{"timestamp": "asc"}], "search_after": [1627891234567] } correctly uses search_after with a numeric array and matching sort order.
  5. Quick Check:

    Check for array format and matching sort [OK]
Quick Trick: Always use array for search_after matching sort fields [OK]
Common Mistakes:
MISTAKES
  • Using a string instead of an array for search_after
  • Omitting the sort clause when using search_after
  • Mismatching sort order and search_after values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes