Find the count of nested field

(ganeshbabu) #1

My document "abc" is in the below format,

"name": "abc",
"age": 25,
"sub": [
"sub_id": 12,
"sub": "english",
"mark": 89
"sub_id": 13,
"sub": "science",
"mark": 99
"sub_id": 14,
"sub": "maths",
"mark": 100

From the above json I need to get the count of sub_id [e.g., count(sub_id) = 3] for a specific json document. Can anyone tell me the elastic search query to get the count. Like GET es_stud/subject/_search

(Mark Walkom) #2

You want to get a total of however many times a sub_id is mentioned in a doc?

(ganeshbabu) #3

Yes @warkolm I want to get total count of sub_id in a document.

(system) #4