# Kibana Nested Query

**URL:** https://discuss.elastic.co/t/kibana-nested-query/117716
**Category:** Kibana
**Created:** [January 30, 2018, 11:10pm UTC](https://discuss.elastic.co/t/kibana-nested-query/117716 "2018-01-30T23:10:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Godacre](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@Godacre](https://discuss.elastic.co/u/Godacre)
#### Post date: [January 30, 2018, 11:10pm UTC](https://discuss.elastic.co/t/kibana-nested-query/117716/1 "2018-01-30T23:10:16Z")

</div>

Hi,

I am currently trying to set up a visualisation in Kibana to monitor the overall number of requests entering the system. I have been looking around extensively to try and find some guidance on how to reach my desired outcome, however I believe Kibana may not be able to do exactly what I want here. To set the scene, I will first explain a few things about the scenario:

- I have multiple different servers which can handle requests - if it is appropriate - certain requests can be internally routed to another server depending on the type of request. There is a tag set up in Elastic for this e.g. (server:"server\_name")
- Requests receive a unique identifier when they enter the system and this is set up as a tag in Elastic e.g. (id:"unique\_id")
- The requests receive a tag in Elastic to specify the log type e.g. (logtype:"log\_type")

I am trying to put a query together to satisfy the following logic (I will write this in SQL for simplicity - note that any bold text indicates a tag in Kibana):

SELECT COUNT(DISTINCT( **id** ))  
FROM [elastic logs]  
WHERE **logtype** = "log\_type"  
AND **id** NOT IN (SELECT **id**  
FROM [elastic logs]  
WHERE **server** IN ("server1","server2",...));

Any assistance would be much appreciated.

Cheers,  
Jack

---

<div class="post-metadata">

### Author: ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)
#### Post date: [January 31, 2018, 3:20am UTC](https://discuss.elastic.co/t/kibana-nested-query/117716/2 "2018-01-31T03:20:12Z")

</div>

Elasticsearch does not support sub-queries. In Kibana you could create a search, hardcoding the list of internal servers and re-use it for your visualizations. When in Discover, you can click on Add Filter to create this list using the UI or construct the query manuallyn using a must\_not terms filter. You could either manually update this or it's possible to programmatically using our Saved Objects API.

For the Saved Object API, you could use the [original PR](https://github.com/elastic/kibana/pull/11632) to understand the interface. We should have documenation up for it shortly.

---

<div class="post-metadata">

### Author: ![Godacre](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@Godacre](https://discuss.elastic.co/u/Godacre)
#### Post date: [January 31, 2018, 4:02am UTC](https://discuss.elastic.co/t/kibana-nested-query/117716/3 "2018-01-31T04:02:59Z")

</div>

Hi Tyler,

Thanks for the response 🙂 I will have a play around with making some lists and see if I can reach my desired outcome.

Jack

---

<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: [February 28, 2018, 4:03am UTC](https://discuss.elastic.co/t/kibana-nested-query/117716/4 "2018-02-28T04:03:04Z")

</div>

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