1

I want to gather statistics over a field names "CpuEff" for each unique field "DESIRED_CMS_Dataset". So I wrote this,

curl -XPOST 'http://localhost:9200/cms-2016-03-30/job/_search?pretty=true' -D'
{
        "aggregations" : {
                "data" : {
                  "terms": {
                        "field": "DESIRED_CMSDataset"
                        "order": {
                                "cnt" : "desc"
                        }
                   },
                   "aggregations" : {
                        "data_stats" : {
                                "extended_stats" : { "field" : "CpuEff" }
                        }
                   }
                 }
        }
}'

This gives an neither gives me the statistics nor gives me just the field DESIRED_CMSDataset. Instead I get a bunch of

{
      "_index" : "cms-2016-03-30",
      "_type" : "job",
      "_id" : "[email protected]#6248657.0#1459314096",
      "_score" : 1.0,
      "_source" : {
        "CoreHr" : 1.1066666666666667,
        "DataCollectionDate" : 1459318128,
        "JobStartDate" : 1459314144,
        "Requirements" : false,
...

So I would like to fix my query so that I only see DESIRED_CMSDataset and the results that this says I should get (ie avg, sum, ...) for each unique value of DESIRED_CMSDataset.

1 Answer 1

2

By default elasticsearch returns 20 documents in search request you can add "size" :0 to output only aggregations

curl -XPOST 'http://localhost:9200/cms-2016-03-30/job/_search?pretty=true' -D'
{
        "size": 0, 
        "aggs" : {
                "data" : {
                  "terms": {
                        "field": "DESIRED_CMSDataset"
                        "size": 0,
                        "order": {
                                "_count" : "desc"
                        }
                   },
                   "aggs" : {
                        "data_stats" : {
                                "extended_stats" : { "field" : "CpuEff" }
                        }
                   }
                 }
        }
}'
Sign up to request clarification or add additional context in comments.

3 Comments

Perfect except I only get 10 aggregations back. I want all of them for every possible unique DESIRED_CMSDataset. Solving this will fully solve my problem. Thanks
you can use size field in terms aggregation. If set to 0, the size will be set to Integer.MAX_VALUE. I have updated the answer.
Wow! Thank you. You are the first person who has actually answered any of my ElasticSearch questions on StackOverflow. Most people just point me documentation that just confuses me more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.