# Aggregation query syntax - assistance needed

**URL:** <https://discuss.elastic.co/t/aggregation-query-syntax-assistance-needed/240270>\
**Category:** Elasticsearch\
**Created:** [July 8, 2020, 6:14am UTC](https://discuss.elastic.co/t/aggregation-query-syntax-assistance-needed/240270 "2020-07-08T06:14:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [July 8, 2020, 6:14am UTC](https://discuss.elastic.co/t/aggregation-query-syntax-assistance-needed/240270/1 "2020-07-08T06:14:09Z")

</div>

Hello  
I am trying to get docs that answer the query.  
But, also want to get 1 doc of each type.  
For example, retrieve all the hostnames that have diskspace\_usage \> 0.3  
With the following I am getting the correct results but with repetition.  
I want to show each hostname once.  
How should I write the query?

```auto
GET _search
{
"aggs" : {
    "hostnames" : {
            "terms" : { "field" : "hostname" ,
                        "size": 1
            } 
        }
    },
  "query": {
    "bool": {
      "must": [
            { "match": { "agent_type": "metricbeat" }},
            { "match": { "metricset_name": "filesystem" }},
			{"range": {"diskspace_usage": {
                                        "from": 0.3,
                                        "to": 1.0,
                                        "include_lower": true,
                                        "include_upper": false
                                    }
                                }
			},
                {
                    "range": {
                        "@timestamp": {
                            "from": "now-15m",
                            "to": null,
                            "include_lower": true,
                            "include_upper": true
                        }
                    }
                }
          ]
        }
    }
}

```

Cheers! ✈

---

<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:** [August 5, 2020, 6:14am UTC](https://discuss.elastic.co/t/aggregation-query-syntax-assistance-needed/240270/2 "2020-08-05T06:14:20Z")

</div>

Closed on August 5, 2020, 6:14am UTC

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