Hi guys,
We quiet liked the Search After feature and we were wondering if it would be a big effort to do the Search Before feature?
To answer the question: Why would you need that?
Let's take the comments in Facebook for exemple.
It loads the first couple comments, then as you read then it loads the following ones. It is therefore paginated and can perfectly be achieved with the Search After feature.
Now if I receive a notification we jump directly to the comment and then we may want to see the previous comments.
Cheers
The way to do this is to use search after, but to sort in reverse order.
@clintongormley That's the way I'm trying to implement but it's super difficulte as I want to generalise that for many requests. And in this implementation I get the opaque SearchRequestBuilder.
Also the result is sorted in reverse order so I need to somehow reverse again the result once it comes back for ES and again it's almost impossible to encapsulate that in a module that manages Pagination.
But I agree this is a workaround but quiet dirty.
I have a sort by 3 different fields (as in the example below)
"sort":[
{"field1":"asc"},
{"field2":"desc"},
{"field3": "asc"}
]
Now what does it mean to sort this in the reverse order?
Clearly flipping the order for each field doesn't actually make it the right reverse order.
"sort":[
{"field1":"desc"},
{"field2":"asc"},
{"field3": "desc"}
]
is there a composite sort which basically takes the sort operations as one unit, so we can effectively do a forward or reverse sort. I am using the java high level rest client api (code below). Not sure how to associate sort builder as a single unit of all sorts included, so it鈥檚 possible to reverse?
SortBuilder sortBuilder = new FieldSortBuilder("field1");
sortBuilder.order(org.elasticsearch.search.sort.SortOrder.ASC);
SortBuilder sortBuilder1 = new FieldSortBuilder("field2");
sortBuilder1.order(org.elasticsearch.search.sort.SortOrder.ASC);
SortBuilder sortBuilder2 = new FieldSortBuilder("field3");
sortBuilder2.order(org.elasticsearch.search.sort.SortOrder.ASC);
searchSourceBuilder.sort(sortBuilder);
searchSourceBuilder.sort(sortBuilder1);
searchSourceBuilder.sort(sortBuilder2);
Most helpful comment
@clintongormley That's the way I'm trying to implement but it's super difficulte as I want to generalise that for many requests. And in this implementation I get the opaque SearchRequestBuilder.
Also the result is sorted in reverse order so I need to somehow reverse again the result once it comes back for ES and again it's almost impossible to encapsulate that in a module that manages Pagination.
But I agree this is a workaround but quiet dirty.