2

Consider the following data

POST programming/languages/1
{
  "name":"java",
  "type":"general_purpose"
}
POST programming/languages/2
{
  "name":"javascript",
  "type":"scripting"
}
POST programming/languages/3
{
  "name":"c",
  "type":"general_purpose"
}

GET programming/languages/_search
{
  "query": {
   "match": {
    "type":"general_purpose"
   }
  }
}

If I need to find the docs which has more than one match of the field type, how do that in elasticsearch ?

Normally using group by with having clause we can achieve this in SQL. Can we achieve this in elasticsearch?

Hariharan
  • 881
  • 1
  • 13
  • 25

1 Answers1

4

Hi you can use the top_hits query, it does not suit situation where you expect to find a lot of documents for a term. Try it in your own situation. But I think this query can find what you want.

GET /programming/languages/_search?search_type=count
{
  "aggs": {
    "byTop": {
      "terms": {
        "field": "type",
        "min_doc_count": 2,
        "size": 10
      },
      "aggs": {
        "theTop": {
          "top_hits": {
            "size":5
          }
        }
      }
    }
  }
}
Jettro Coenradie
  • 4,735
  • 23
  • 31
  • 1
    For equality min_doc_count works perfectly , but if we want greater than or less than, whether it is possible? – Hariharan Mar 02 '15 at 06:01