How to find count of each field in a elastic search document


(Nitedra Kumar) #1

I have document like given below

{"host":"xxx",

"sessionId":"xxx",

"day1":"10",

"day2":"30",

"day3":"20",

"day4":"50",

"day5":"10",

"day6":"20",

"day7":"80"}

day field is dynamic and may or may not available for each day. want to write query to fetch all sessionId where occurrence of day field > 4

for example given doc is not eligible for query result while above doc is eligible

{"host":"xxx",

"sessionId":"xxx",

"day1":"10",

"day2":"30",

"day6":"20",

"day7":"80"}


(ddorian43) #2

Hi,

Can you make a script, that has access to the _source, and will just iterate and count the number of fields that start with "day" ?


(Nitedra Kumar) #3

i am new in elasticsearch and need java code to count all the field start with "day".


(system) #4