# Using partition returns unexpected result

**URL:** <https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767>\
**Category:** Elasticsearch\
**Created:** [July 23, 2019, 8:44am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767 "2019-07-23T08:44:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jadore](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jadore/32/45191_2.png) [@jadore](https://discuss.elastic.co/u/jadore)\
**Post date:** [July 23, 2019, 8:44am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767/1 "2019-07-23T08:44:23Z")

</div>

Query does not gives result as expected:

when query without using partition the query will return correct result: it will return the max view of all products.

But when partition is used, it won't return the max total view.

```auto
    get product/_search
    {
      "size": 0,
      "query": {
        "match_all": {}
      },
      "aggs": {
        "cars": {
          "terms": {
            "field": "type.keyword",
            "include": {
              "partition": 0,
              "num_partitions": 5
            },
            "order": {
              "productHits": "desc"
            }
          },
          "aggs": {
            "productHits": {
              "sum": {
                "field": "hits"
              }
            }
          }
        }
      }
    }

```

expected:

```auto
    "buckets" : [
            {
              "key" : "a car",
              "doc_count" : 383,
              "productHits" : {
                "value" : 209.0
              }]

```

actual:

```auto
    "buckets" : [
            {
              "key" : "another car",
              "doc_count" : 383,
              "productHits" : {
                "value" : 9.0
              }]

```

a car has the highest hits of all.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 23, 2019, 8:55am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767/2 "2019-07-23T08:55:57Z")

</div>

That is working as expected.  
The ordering is guaranteed within partitions not across partitions.  
Ultimately partitions are a way of dealing with high cardinality data spread across a distributed system and has limitations. To overcome these limitations you have to tackle the physics of the problem and move related data closer together at index time either through custom routing of docs, centralisation in one shard or building an entity-centric index using something like [dataframes](https://www.elastic.co/guide/en/elasticsearch/reference/master/preview-data-frame-transform.html)

---

<div class="post-metadata">

**Author:** ![jadore](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jadore/32/45191_2.png) [@jadore](https://discuss.elastic.co/u/jadore)\
**Post date:** [July 23, 2019, 10:24am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767/3 "2019-07-23T10:24:33Z")

</div>

What we're trying to do is create buckets which we can sum all views of our products into its own category and it should work with pagination.

Do you have any recommended way how we can achieve this?

["Omega", "Rolex", "Seiko"]  
["BMW", "Honda"]

result:

buckets: [  
watch: {  
total\_view: 1234  
},  
car: {  
total\_view: 222  
}  
]

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 23, 2019, 10:27am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767/4 "2019-07-23T10:27:39Z")

</div>

Try run this wizard - it has many of the questions that I'd typically ask to steer you towards an answer:  
[https://plnkr.co/edit/iJSFP8eRrhC7l7Hx2XOL?p=preview](https://plnkr.co/edit/iJSFP8eRrhC7l7Hx2XOL?p=preview)

---

<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:** [August 20, 2019, 10:27am UTC](https://discuss.elastic.co/t/using-partition-returns-unexpected-result/191767/5 "2019-08-20T10:27:41Z")

</div>

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