Yes, easily.  Aggregations are really powerful.  Here's an example:

# First insert some data
curl -XPUT "http://localhost:9200/myindex/mytype/1"; -d'
{
  "created": "2014/03/10 12:05:00",
  "somefield": 10
}'

curl -XPUT "http://localhost:9200/myindex/mytype/2"; -d'
{
  "created": "2014/03/10 12:05:00",
  "somefield": 5
}'

curl -XPUT "http://localhost:9200/myindex/mytype/3"; -d'
{
  "created": "2014/03/9 12:05:00",
  "somefield": 5
}'


# Then return all results in the last 28 days
# and calculate the avg per hour
curl -XGET "http://localhost:9200/myindex/mytype/_search"; -d'
{
  "query": {
    "range": {
      "created": {
        "gte": "now-28d/d",
        "to": "now"
      }
    }
  },
  "aggs": {
    "per_hour": {
      "date_histogram": {
        "field": "created",
        "interval": "hour"
      },
      "aggs": {
        "rolling_avg": {
          "avg": {
            "field": "somefield"
          }
        }
      }
    }
  }
}'



On 11 March 2014 09:26, Simon Cast <simon.c...@gmail.com> wrote:

> Hi,
>
> I'm looking at using the new aggregations module of Elasticsearch to
> produce some metrics for my application.
>
> I want to calculate the rolling average for every hour in the last 28 days
> and then plot these on a chart. I can see how this could be done using a
> query per hour for the last 28 days. This seems problematic in terms of
> load and performance. Can this be done using a single query?
>
> Regards,
>
> Simon
>
>
>  --
> 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/d0a2dba7-f5a5-4944-ae0e-c6771b43ad6c%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/d0a2dba7-f5a5-4944-ae0e-c6771b43ad6c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CAPt3XKS-tpSZMwM8WVBuXg%3Dez618xbTnCSTXAkWGrFsSxmdnew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to