1

my index consists of documents like this one

{
"clientPorttopKByCount": [
            {
                "value": 1,
                "key": "41770"
            },
            {
                "value": 1,
                "key": "41791"
            }
],
"timestamp": 1574335260000,
}

Requirement : group by clientPorttopKByCount.key and sum the clientPorttopKByCount.value for every 60 seconds of histogram

My current ES Query : ( It is giving the wrong sum )

"aggregations": {
"clientPorttopKByCount.key": {
  "nested": {
    "path": "clientPorttopKByCount"
  },
  "aggregations": {
    "orders": {
      "terms": {
        "field": "clientPorttopKByCount.key",
        "size": 5000,
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      },
      "aggregations": {
        "records": {
          "reverse_nested": {

          },
          "aggregations": {
            "histogram": {
              "histogram": {
                "field": "timestamp",
                "interval": 60000.0,
                "offset": 0.0,
                "order": {
                  "_key": "asc"
                },
                "keyed": false,
                "min_doc_count": 0
              },
              "aggregations": {
                "clientPorttopKByCount.key": {
                  "nested": {
                    "path": "clientPorttopKByCount"
                  },
                  "aggregations": {
                    "clientPorttopKByCount.value_sum": {
                      "sum": {
                        "field": "clientPorttopKByCount.value"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
}

the problem: it is giving the sum of all the histogram minutes for a single key.

Please help me to solve this.

Yamuna
  • 11
  • 3

0 Answers0