How can i write these sql query in kibana?

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.

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 on the "Description" field; or
  2. Re-map the "Description" field as both a text field and keyword field using the fields parameter.

Note, this may dramatically increase your index size.

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