# How to write search queries in kibana using Query DSL for aggregation

**URL:** <https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690>\
**Category:** Kibana\
**Created:** [June 15, 2015, 12:09pm UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690 "2015-06-15T12:09:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bene\_jo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bene_jo/32/666_2.png) [@bene\_jo](https://discuss.elastic.co/u/bene_jo)\
**Post date:** [June 15, 2015, 12:09pm UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/1 "2015-06-15T12:09:12Z")

</div>

I am working on ELK stack to process Apache access logs. Spent a lot of time understanding Query DSL format so that more complex queries can be written. Currently am facing issues with running the queries in kibana interface but the same queries work just fine when sent using curl from command line.

Kibana version: 4.1.0  
Elasticsearch version: 1.6.0  
Java: 1.8.0\_45

Using curl(working):  
curl -XGET [http://localhost:9200/cars/transactions/\_search?search\_type=count](http://localhost:9200/cars/transactions/_search?search_type=count) -d '{  
"aggs" : {  
"colors" : {  
"terms" : {  
"field" : "color"  
}}}}'  
Used data from [here](https://www.elastic.co/guide/en/elasticsearch/guide/master/_aggregation_test_drive.html#_aggregation_test_drive).

Using kibana(not working):  
{ "aggs" : { "colors" : { "terms" : { "field" : "color" } } } }

Error:  
org.elasticsearch.index.query.QueryPassingException:[.kibana] No query registered for [aggs]

Below are some of the queries I manage to run successfully in kibana using Query DSL on apache access log data,

1. {"filtered":{"filter":{"bool":{"must":{"terms":{"verb":["get"]}}}}}}
2. {"filtered":{"filter":{"bool":{"must\_not":{"terms":{"agent":["crawler","spider","nagios"]}}}}}}

Any help will be greatly appreciated. I have already searched google about it for hours but without luck. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [June 17, 2015, 4:14am UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/2 "2015-06-17T04:14:00Z")

</div>

Only the query/filter part of the query DSL works in the Kibana search bar - it allows you to filter down the set of returned documents. To apply aggregations in Kibana, you have to use the visualization builder in the Visualize tab. Under the "buckets" section, look for the "terms" aggregation.

---

<div class="post-metadata">

**Author:** ![bene\_jo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bene_jo/32/666_2.png) [@bene\_jo](https://discuss.elastic.co/u/bene_jo)\
**Post date:** [July 6, 2015, 9:05am UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/3 "2015-07-06T09:05:10Z")

</div>

Thank you, I got that to work. 😄

---

<div class="post-metadata">

**Author:** ![shinesamuel1989](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@shinesamuel1989](https://discuss.elastic.co/u/shinesamuel1989)\
**Post date:** [November 12, 2015, 11:07am UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/4 "2015-11-12T11:07:34Z")

</div>

@bene_jo : Could you please help on the as how did you go about it? I am trying doing the same but was unable to do aggregation using below query.

{  
"size": 0,  
"query": {  
"query\_string": {  
"query": "\*",  
"analyze\_wildcard": true  
}  
},  
"aggs": {  
"1": {  
"cardinality": {  
"field": "item\_titles.sku\_id"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![nivetha](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nivetha](https://discuss.elastic.co/u/nivetha)\
**Post date:** [January 13, 2016, 4:54am UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/5 "2016-01-13T04:54:03Z")

</div>

bene\_jo even am facing the same issue,can you please help me out with this?

---

<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 6, 2017, 2:05pm UTC](https://discuss.elastic.co/t/how-to-write-search-queries-in-kibana-using-query-dsl-for-aggregation/2690/6 "2017-07-06T14:05:13Z")

</div>


