I've been trying for days to get group+sort working with @search-ui, with either the app-search connector or the elasticsearch connector with limited success with both.
Originally I used the app-search connector and set the group
on the query:
group: {
collapse: true,
field: 'card_code_rarity',
},
This almost gives me the result I want, with each search result containing a _group
property with the documents in the group. The only additional thing I need is to sort by the count of these documents. If the following worked it would be fantastic:
group: {
collapse: true,
field: 'card_code_rarity',
},
sort: [
{ '_group.length': 'desc' },
],
But it doesnt. After hitting non-step dead-ends I decided to try to Elasticsearch connector with search-ui.
I can get some form of a usable end result with the following in POSTMAN:
aggs: {
card_code_rarity: {
terms: {
field: "card_code_rarity",
order: {
"_count": "desc"
}
},
aggs: {
my_docs: {
top_hits: {
sort: [
{
"selling_price": { "order": "desc" }
}
]
}
}
}
}
},
However this part of the query gets completely omitted by the Elasticsearch connector, it seems to not have support for this.... and it wont even forward the params as-is.
This connector also doesn't seem to have a beforeSearch
hook like the app-search one, and it's not easy to extend it since it doesnt export handleSearchRequest()
. So what to do?
Ideally, I can go back to using AppSearch connector and get the sorting to work somehow.
Otherwise how can I get the aggregate query to work with the Elasticsearch connector?
Actually, would be nice to know how to do it with either connector in case I need to switch again for some other limitation.