I am trying to sort search results by a date across multiple pages of results. Sorting is working within each page, is there a way to sort across the entire set?
For example: If page 1 has items from Feb 13 through Feb 1st; the second page should not have items after Feb 1st.
Here is a brief snippet of the request that I am sending. I have also tried sorting by date then _score, but that produced even stranger results (primarily, the sort order was the same).
{
"query": {
"from": 0,
"size": 24
"sort": [
"published_on": {
"missing": "_last",
"ignore_unmapped": true,
"order": "desc"
}
]
"custom_filters_score": {
"query": {
"bool": {
"must": [
{
"match": {
"content": "Some query"
}
}
]
... more ...
}
},
"filters": [
{
"filter" => {
"type" => {
"value" => "cats"
}
},
"boost" => 2
}
... more ...
]
}
}
}
Any thoughts? Thanks in advance!
Each time when we search something on the web, it returns a lot of results. These results can be in hundreds or thousands or sometimes in lakhs, which are distributed on several pages. Each page has multiple records. This mechanism is known as pagination.
To page through a larger set of results, you can use the search API's from and size parameters. The from parameter defines the number of hits to skip, defaulting to 0 . The size parameter is the maximum number of hits to return. Together, these two parameters define a page of results.
Deep pagination means to allow the user access to too many pages. You should never give your users access to all the pages of their search request.
By default, Elasticsearch limits the number of results to 10, so if you can have more than 10 results, look at the value of total for the precise number of documents that match your search criteria. As you saw previously, to change the number of results returned, use the size parameter.
I was not multiplying the page index by the number of items on the page. I'm not sure how I missed the same entires on every page, moved up by a single spot.
I'm sure this will resolve all of the other odd issues that I have been dealing with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With