Request documents based on the sum of nested fields - elasticsearch

I am new to Elastic and I was trying to figure out if it is possible to query documents based on the sum or the number of nested fields inside them. All the research I have done so far will say that this is not the case, but maybe there is a way around this?

I know about aggregations , but they output the total instead of changing the search results based on the total.

For example, I have a dataset that looks like this:

{
  "records": [
    {
      "JhseTzYuOF_first": "Liam",
      "JhseTzYuOF_last": "McAneny",
      "record_activity": [
        {
          "category": "YfV068",
          "comment": "Appeal",
          "created": "2015-06-14T21:41:22+10:00",
          "value": 15
        }
      ],
      "$id": "-Jr8G3YEMjafAvRP1a8I"
    },
    {
      "JhseTzYuOF_first": "Pha-Hai",
      "JhseTzYuOF_last": "Nguyen",
      "record_activity": [
        {
          "category": "YfV068",
          "comment": "Donated",
          "created": "2015-06-14T13:49:23+10:00",
          "value": 10
        },
        {
          "category": "YfV068",
          "comment": "Donated",
          "created": "2015-06-14T13:49:55+10:00",
          "value": 15
        }
      ],
      "$id": "-Jr8G3Y7JQrBTb-cpFsT"
    }
  ]
}

      

record_activity

appears as nested and I can query for it, but I was hoping I could do something like:

show all where sum of record_activity.value > 20

Any ideas how to achieve this via ElasticSearch?

+3


source to share





All Articles