Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get counting data by comma-separated value field in Elastic Search

Need Help.

I have data in elasticsearch, field "interests" like this:

{
"interests": "A,C,D,E"
},
{
"interests": "B,C,D"
},
{
"interests": "A,B,C,D,E"
},
{
"interests": "D,E"
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to get data like this:
{
"key": "A",
"doc_count": 2
},
{
"key": "B",
"doc_count": 2
},
{
"key": "C",
"doc_count": 3
},
{
"key": "D",
"doc_count": 4
},
{
"key": "E",
"doc_count": 3
}

what steps should I take.
Thank you.

>Solution :

A simple terms aggregation should do the job:

POST test/_search
{
  "aggs": {
    "interests": {
      "terms": { "field": "interests" }
    }
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading