-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
The top hits aggregation is quite a powerful feature of Elasticsearch. The aggregation support is a step closer to get this functionality, but it would be awesome to make these top hits reactive and as a built it feature.
Example:
engine: new EasySearch.ElasticSearch({
tophits: [{ field: 'category', size: 5, limit: 10 }]
})This would generate tophits for 5 of the most popular categories. This would result in an ES aggregation that looks like:
{
"top_category_hits": {
"terms": {
"field": "category",
"order": {
"max_score": "desc"
},
"size": 5
},
"aggs": {
"top_category_hits": {
"top_hits": {
"track_scores": true,
"sort": [{
"_score": {
"order": "desc"
}
}],
"_source": {
"include": [
"name", "category", "score" // example fields
]
},
"size": 10
}
},
"max_score": {
"max": {
"script": "_score"
}
}
}
}
}The tophits can then be retrieved by:
var cursor = index.search('test');
// get all aggregations
var types = cursor.getTophitsTypes();
types.forEach(function (type) {
var tophits = cursor.getTophits(type);
console.log(tophits.fetch());
})I'd like some feedback on this 😄