Re: Nested list aggregation

2015-03-25 Thread Masaru Hasegawa
Hi,

If you define "stages" as nested type, query like this should work:

{
  "query": {
"match_all": {}
  },
  "aggs": {
"0": {
  "nested": {
"path": "msg.stat.stages"
  },
  "aggs": {
"1": {
  "terms": {
"field": "stage"
  },
  "aggs": {
"2": {
  "sum": {
"field": "duration"
  }
}
  }
}
  }
}
  }
}


Masaru

On March 24, 2015 at 21:26:33, Vasily Kirichenko (vas...@gmail.com) wrote:

I have documents like this in my index:

{
   "time": "2015-03-24T08:24:55.9056988",
   "msg": {
        "corrupted": false,
        "stat": {
            "fileSize": 10186,
            "stages": [
                {
                   "stage": "queued",
                   "duration": 420
                },
                {
                   "stage": "validate",
                   "duration": 27
                },
                {
                   "stage": "cacheFile",
                   "duration": 87
                },
                {
                   "stage": "sendResult",
                   "duration": 1332
                }
           ]
       }
   }
}

I'd like to calculate sum(msg.stat.stages.duration) grouped by 
msg.stat.stages.stage.
I tried the following:

{
  "size": 0,
  "aggs": 
  {
    "1": 
    {
      "terms": { "field": "msg.stat.stages.stage" },
      "aggs":
      {
        "2":
        {
          "nested": { "path": "stat.stages" },
          "aggs": 
          {
            "3": {
              "sum": {
                "field": "stat.stages.duration"
              }
            }
          }
        }
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

and got:

{
   "took": 6,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "1": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "2": {
                  "doc_count": 0
               },
               "key": "cachefile",
               "doc_count": 1
            },
                      {
               "2": {
                  "doc_count": 0
               },
               "key": "queued",
               "doc_count": 1
            },
                 {
               "2": {
                  "doc_count": 0
               },
               "key": "sendresult",
               "doc_count": 1
            },
            {
               "2": {
                  "doc_count": 0
               },
               "key": "validate",
               "doc_count": 1
            }
         ]
      }
   }
}

which is not what I expected. Any ideas?

Thanks!
--
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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/22173f85-6d94-4b29-a9f5-b13c46a4850d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/etPan.55126f6c.238e1f29.166%40citra-2.local.
For more options, visit https://groups.google.com/d/optout.


Nested list aggregation

2015-03-24 Thread Vasily Kirichenko
I have documents like this in my index:

{
   "time": "2015-03-24T08:24:55.9056988",
   "msg": {
"corrupted": false,
"stat": {
"fileSize": 10186,
"stages": [
{
   "stage": "queued",
   "duration": 420
},
{
   "stage": "validate",
   "duration": 27
},
{
   "stage": "cacheFile",
   "duration": 87
},
{
   "stage": "sendResult",
   "duration": 1332
}
   ]
   }
   }
}

I'd like to calculate sum(msg.stat.stages.duration) grouped by 
msg.stat.stages.stage.
I tried the following:

{
  "size": 0,
  "aggs": 
  {
"1": 
{
  "terms": { "field": "msg.stat.stages.stage" },
  "aggs":
  {
"2":
{
  "nested": { "path": "stat.stages" },
  "aggs": 
  {
"3": {
  "sum": {
"field": "stat.stages.duration"
  }
}
  }
}
  }
}
  },
  "query": {
"match_all": {}
  }
}

and got:

{
   "took": 6,
   "timed_out": false,
   "_shards": {
  "total": 5,
  "successful": 5,
  "failed": 0
   },
   "hits": {
  "total": 1,
  "max_score": 0,
  "hits": []
   },
   "aggregations": {
  "1": {
 "doc_count_error_upper_bound": 0,
 "sum_other_doc_count": 0,
 "buckets": [
{
   "2": {
  "doc_count": 0
   },
   "key": "cachefile",
   "doc_count": 1
},
  {
   "2": {
  "doc_count": 0
   },
   "key": "queued",
   "doc_count": 1
},
 {
   "2": {
  "doc_count": 0
   },
   "key": "sendresult",
   "doc_count": 1
},
{
   "2": {
  "doc_count": 0
   },
   "key": "validate",
   "doc_count": 1
}
 ]
  }
   }
}

which is not what I expected. Any ideas?

Thanks!

-- 
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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/22173f85-6d94-4b29-a9f5-b13c46a4850d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.