3ms1
(Emrah)
November 23, 2018, 10:33am
1
Hi,
How I can get sorted bucket by prefix?
For example, score it is higher for "Buffalo" and but I want results with "Fal..." in the beginning to be on top.
If I set include in terms then Buffalo won't appear
Should I achieve this using some sort of script?
Thanks
Can you share the query you are using? Are you trying to improve the ranking of search hits, or the sorting of aggregation results?
If you're trying to order the bucket results for display purposes, the bucket_sort
pipeline agg may do what you need
3ms1
(Emrah)
December 1, 2018, 12:20am
3
Sure, below you may find the agg I use.
Because there are 4 buckets I can not do sorting and pagination .
"aggs": {
"prefix": {
"filter": {
"prefix": {
"name": {
"value": "in"
}
}
},
"aggs": {
"platforms": {
"terms": {
"field": "name",
"size": 100,
"include": "in.*",
"order": {
"_key": "asc"
}
},
"aggs": {
"platform": {
"top_hits": {
"_source": true,
"size": 1
}
}
}
}
}
},
"second": {
"filter": {
"wildcard": {
"name": "* in*"
}
},
"aggs": {
"platforms": {
"terms": {
"field": "name",
"size": 100,
"order": {
"_key": "asc"
}
},
"aggs": {
"platform": {
"top_hits": {
"_source": true,
"size": 1
}
}
}
}
}
},
"middle": {
"filter": {
"wildcard": {
"name": "*in*"
}
},
"aggs": {
"platforms": {
"terms": {
"field": "name",
"size": 100,
"order": {
"_key": "asc"
}
},
"aggs": {
"platform": {
"top_hits": {
"_source": true,
"size": 1
}
}
}
}
}
},
"suffix": {
"filter": {
"wildcard": {
"name": "*in"
}
},
"aggs": {
"platforms": {
"terms": {
"field": "name",
"size": 100,
"order": {
"_key": "asc"
}
},
"aggs": {
"platform": {
"top_hits": {
"_source": true,
"size": 1
}
}
}
}
}
}
}
system
(system)
Closed
December 29, 2018, 12:20am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.