# How can i write these sql query in kibana?

**URL:** <https://discuss.elastic.co/t/how-can-i-write-these-sql-query-in-kibana/187208>\
**Category:** Kibana\
**Created:** [June 25, 2019, 1:13am UTC](https://discuss.elastic.co/t/how-can-i-write-these-sql-query-in-kibana/187208 "2019-06-25T01:13:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pramod\_Thakur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pramod_thakur/32/48428_2.png) [@Pramod\_Thakur](https://discuss.elastic.co/u/Pramod_Thakur)\
**Post date:** [June 25, 2019, 1:13am UTC](https://discuss.elastic.co/t/how-can-i-write-these-sql-query-in-kibana/187208/1 "2019-06-25T01:13:31Z")

</div>

How can I write these following query in kibana?

```
SELECT distinct description FROM customers;
select description,count(*) from customers;

```

I am trying with following but not getting expected result.

1st Query

```
GET customers/_search
{
  "aggs": {
    "distinct_terminals": {
      "cardinality": {
        "field":"description" // and tried with "description.keyword"
      }
    }
  }
}

```

2nd Query

```
GET customers/_search{
"size": 0,
  "aggs": {
    "country_detail": {
      "terms": {
        "field": "Country.keyword"
      }
    }
  }
}

```

2nd query return result as expected but when I was trying to perform this query on a field like a description. it stops working. i.e.

```
GET customers/_search{
"size": 0,
  "aggs": {
    "description_detail": {
      "terms": {
        "field": "Description.keyword"
      }
    }
  }
}

```

Description cannot be 2 3 words. it should be more than that, maybe in a paragraph.

---

<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:** [June 25, 2019, 3:17pm UTC](https://discuss.elastic.co/t/how-can-i-write-these-sql-query-in-kibana/187208/2 "2019-06-25T15:17:44Z")

</div>

It sounds like your "Description" field is mapped as `{ "type": "text" }` in Elasticsearch. `text` fields can not be used with Terms aggregations. You might consider re-mapping your Description field in one of two ways:

1. [Enable fielddata](https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html) on the "Description" field; or
2. Re-map the "Description" field as both a `text` field and `keyword` field using the [`fields` parameter](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html).

Note, this may dramatically increase your index size.

---

<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 23, 2019, 3:17pm UTC](https://discuss.elastic.co/t/how-can-i-write-these-sql-query-in-kibana/187208/3 "2019-07-23T15:17:53Z")

</div>

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