Search code examples
elasticsearchfaceted-search

elasticsearch: is it possible to order aggregations?


Can I add weight to each aggregation to make sure that they return in certain order, for example: category, manufacturer, color instead of in the order shown below:

{
    "aggs": {
        "category": { "terms": { "field": "category" } },
        "manufacturer": { "terms": { "field": "manufacturer" } },
        "color": { "terms": { "field": "color" } }
    }
}

// results

"color": {
    "buckets": [ ... ]
}
"category": {
    "buckets": [ ... ]
}
"manufacturer": {
    "buckets": [ ... ]
}

Solution

  • Can I add weight to each aggregation to make sure that they return in certain order, for example: category, manufacturer, color instead of in the order shown below

    The response is JSON and JSON/JavaScript object keys order is undefined.

    Source: http://www.json.org/

    An object is an unordered set of name/value pairs.