# Aggregations from REST-call

**URL:** <https://discuss.elastic.co/t/aggregations-from-rest-call/90299>\
**Category:** Elasticsearch\
**Created:** [June 21, 2017, 1:47pm UTC](https://discuss.elastic.co/t/aggregations-from-rest-call/90299 "2017-06-21T13:47:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eebee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eebee/32/26799_2.png) [@eebee](https://discuss.elastic.co/u/eebee)\
**Post date:** [June 21, 2017, 1:47pm UTC](https://discuss.elastic.co/t/aggregations-from-rest-call/90299/1 "2017-06-21T13:47:41Z")

</div>

I have constructed a search in Kibana Dev-tool, that gives me the respond I'm looking for. In there I have an aggregation:

```auto
GET /monitor/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": {"_type": "ActivitySummary"} } ],
      "should": [
        { "match": {"activityName": "Formulär"} },
        { "match": {"activityName": "Beslut"} }
      ],
    "minimum_should_match" : 1
    }
  },
  "sort": {"taskStartTime": { "order": "asc" }},
  "_source": ["taskStartTime", "taskCompletedTime", "activityName", "taskInstanceId", "processInstanceId"],
  "size": 0,
  "aggs": {
    "days": {
      "date_histogram": {
        "field": "taskStartTime",
        "interval": "day"
      }
    }
  }
}

```

Is there any way to call for that aggregation in a REST-request in the [http://localhost:9200/monitor/\_search?q=](http://localhost:9200/monitor/_search?q=)...-format?  
How do I do that?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 23, 2017, 2:46pm UTC](https://discuss.elastic.co/t/aggregations-from-rest-call/90299/2 "2017-06-23T14:46:06Z")

</div>

Yep! DevTools actually has an option to do that automatically for you. If you click the little wrench icon at the top-right of your query, a drop-down will have the option "Copy as Curl":

 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/3/e34c7f30a60fd987ac7a516868418f3d9ecac3f4.png)

Which gives you:

```auto
curl -XGET "http://localhost:9200/monitor/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must": [
        { "match": {"_type": "ActivitySummary"} } ],
      "should": [
        { "match": {"activityName": "Formulär"} },
        { "match": {"activityName": "Beslut"} }
      ],
    "minimum_should_match" : 1
    }
  },
  "sort": {"taskStartTime": { "order": "asc" }},
  "_source": ["taskStartTime", "taskCompletedTime", "activityName", "taskInstanceId", "processInstanceId"],
  "size": 0,
  "aggs": {
    "days": {
      "date_histogram": {
        "field": "taskStartTime",
        "interval": "day"
      }
    }
  }
}'

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 21, 2017, 2:48pm UTC](https://discuss.elastic.co/t/aggregations-from-rest-call/90299/3 "2017-07-21T14:48:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
