Hello,
I am new to elasticsearch and I am running into issues doing aggregations 
on nested documents. I have an index that uses nested types. The code I 
used to set up my test data set is given here 
- https://gist.github.com/qvin/9911e904c1d127c28dc7
I want to perform bucket aggregations on the nested documents based on 
filters set on the top level documents properties. Here is the query (along 
with the result) that I came up with 
- https://gist.github.com/qvin/a40bd96d6df25d1b31c3
In the output if you notice that the aggregated value is the same (1026) 
for all buckets. I am interested in aggregations per bucket. Please see the 
expected value listed in the gist. Can someone please help me figure this 
out? I also tried using the "nested" aggregation type as shown below but 
this throws an error. 
Any help is appreciated. I would like to solve this without making changes 
to the document schema if possible.
Thanks!

curl -XGET 'http://localhost:9200/testdb/testtable/_search -d '{
  "size": 0,
  "aggs": {
    "report_aggs": {
      "filter": {
        "and": [
          {
            "term": {
              "prop1": "1"
            }
          },
          {
            "term": {
              "prop2": "2"
            }
          },
          {
            "term": {
              "checkflag": "true"
            }
          }
        ]
      },
      "aggs": {
        "report_aggs_nested": {
          "nested": {
            "path": "nesteddocs"
          },
          "aggs": {
            "aggs_sum": {
              "terms": {
                "field": "nesteddocs.dockey"
              },
              "aggs": {
                "docvalsum": {
                  "avg": {
                    "field": "nesteddocs.docvalue"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}'

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/60646a0c-b3c8-404a-aa3f-34457a779ef6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to