# Different results when changing pipeline aggregations order

**URL:** <https://discuss.elastic.co/t/different-results-when-changing-pipeline-aggregations-order/224559>\
**Category:** Elasticsearch\
**Created:** [March 22, 2020, 1:23pm UTC](https://discuss.elastic.co/t/different-results-when-changing-pipeline-aggregations-order/224559 "2020-03-22T13:23:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morteza\_hosseini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/morteza_hosseini/32/53285_2.png) [@morteza\_hosseini](https://discuss.elastic.co/u/morteza_hosseini)\
**Post date:** [March 22, 2020, 1:23pm UTC](https://discuss.elastic.co/t/different-results-when-changing-pipeline-aggregations-order/224559/1 "2020-03-22T13:23:41Z")

</div>

Consider this query:

```auto
GET test-index/_search
{
  "size": 0, 
   "query": {
      "term": {
        "data.category": {
          "value": "light"
        }
      }
   }
   , "aggs": {
     "brand_model": {
       "terms": {"field": "data.brand", "size": 1000, "order": {
         "sort_date": "desc"
       }},
       "aggs": {
         "sort_date": {
           "max": {
             "field": "sort_date"
            }
         },
          "sort_date_bucket_filter": {
            "bucket_selector": {
                "buckets_path": {
                  "sort_date": "sort_date.value"
                },
                "script": "1.584896296672E12 > params.sort_date"
            }
          },
           "sort_date_bucket_sort": {
            "bucket_sort": {
                "sort": [{
                  "sort_date": {"order": "desc"}
                }],
                "size": 10,
                "from": 0
              }
          }
       }
     }
   }
}

```

And when i chenge the order of pipeline aggregations to this:

```auto
GET test-index/_search
{
  "size": 0, 
   "query": {
      "term": {
        "data.category": {
          "value": "light"
        }
      }
   }
   , "aggs": {
     "brand_model": {
       "terms": {"field": "data.brand", "size": 1000, "order": {
         "sort_date": "desc"
       }},
       "aggs": {
         "sort_date": {
           "max": {
             "field": "sort_date"
            }
         },
         "sort_date_bucket_sort": {
            "bucket_sort": {
                "sort": [{
                  "sort_date": {"order": "desc"}
                }],
                "size": 10,
                "from": 0
              }
          },
          "sort_date_bucket_filter": {
            "bucket_selector": {
                "buckets_path": {
                  "sort_date": "sort_date.value"
                },
                "script": "1.584896296672E12 > params.sort_date"
            }
          }
       }
     }
   }
}

```

the result i get is empty (different result!).  
Can anyone explain this? Does ordering has any effect on the aggregations result?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 19, 2020, 1:23pm UTC](https://discuss.elastic.co/t/different-results-when-changing-pipeline-aggregations-order/224559/2 "2020-04-19T13:23:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
