# Custom query to create data table

**URL:** https://discuss.elastic.co/t/custom-query-to-create-data-table/192700
**Category:** Kibana
**Created:** [July 29, 2019, 1:20pm UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700 "2019-07-29T13:20:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [July 29, 2019, 1:20pm UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700/1 "2019-07-29T13:20:13Z")

</div>

Hi

I do have the following custom query and want to create a Data Table visualization from it:

```auto
GET applications_*/_search
{ "size" : "0",
  "aggregations": {
    "by_size": {
      "terms": {
        "field": "Size"
      },
      "aggregations": {
        "distinct_appl": 
                               {
            "cardinality": { "field" : "applname.keyword" }
        },
        "without_a_server_name" : 
         {
            "missing" : { "field" : "server_name" }
         },
         "unique_server_name" : 
         {
            "cardinality" : { "field" : "server_name" }
         }
      }
    }
  }
}

```

The output should be :  
Size, #distinct\_apps, #without\_a\_server\_name,#unique\_server\_name

How can I get this visualized?

Regards Hans

---

<div class="post-metadata">

### Author: ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)
#### Post date: [July 29, 2019, 4:50pm UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700/2 "2019-07-29T16:50:02Z")

</div>

You can achieve the cardinality aggregations by creating "Unique Count" Metrics for those fields in the Data Table visualization.

As far as I can tell, there is not an easy way to add an output showing counts from missing fields in the same visualization. One way to do this is create a copy of the visualization and apply a filter where "server\_name" does not exist.

---

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [July 30, 2019, 10:54am UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700/3 "2019-07-30T10:54:10Z")

</div>

> [@HansPeterSloot](#):
>
> cardinality

Ok  
I'll try.  
Thanks

---

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [July 30, 2019, 12:02pm UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700/4 "2019-07-30T12:02:03Z")

</div>

I managed to do it with Visual Builder.  
With Options you can supply a filter per aggregation.

---

<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 27, 2019, 12:02pm UTC](https://discuss.elastic.co/t/custom-query-to-create-data-table/192700/5 "2019-08-27T12:02:12Z")

</div>

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