Using partition returns unexpected result

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.

    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:

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

actual:

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

a car has the highest hits of all.

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

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
}
]

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

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