Elascticsearch count api returning improper count

Hi All,

Could someone please help me on the below issue.

I have some thousands of documents in my index. When I am hitting count api with a condition where i am providing term query with ten thousand values for a particular field. Its returning ten thousand documents, but total field is showing 10001 as count.

Please help me on this.

Thanks,
Ram Prasad G

Can you share your query and the output? Formatted please with the format button </>

URL: http://localhost:9200/thr/thrtype/_count
Request Body:

{
"query": {
"bool": {
"must": [{
"terms": {
"empcode": ["433530187", "432610600", "429590801", "430060653", "430090661", "431570622", "857070585", "431130381", "435780347", "458180226", "434620051", "429600342", "431240447", "431280698", "430240230", "435300607", "438180957", "434560460", "338690294", "430740047", "434660787", "338680023", "437160645", "430520520", "429780030", "339450857", "436220764", "434330185", "429430187", "434410350", "429420996", "434070300", "431800766", "428670832", "437640252", "435730190", "431220097", "431720691", "339990117", "434660893", "440700219", "435770616", "434140248", "435700947", "338750038", "428640249", "435780554", "338290453", "431140601", "435040623", "338360160", "430570783", "438828709", "429990483", "338340074", "430790112", "338730122", "435450209", "435650905", "437520883", "338580056", "437670075", "430140721", "431520802", "429770580", "428140474", "431940778", "435670790", "437490042", "429400657", "435420144", "429770230", "338670040", "339370847", "435330131", "435480937", "435950368", "435950288", "459170572", "434030539", "430240178", "437640702", "430870375", "437180845", "431090623", "429610253", "434730121", "513890421", "434690963", "433592011", "446150187", "435940179", "339370591", "435870221", "432330178", "429400656", "435860068", "563680482", "434890706", "339670174", "435490460", "339790134", "433730438", "435060636", "430740058", "445430189", "436000858", "434090256", "338360278", "438184587", "428700399", "338310204", "444140388", "435060105", "432360967", "433960017", "433730696", "338840662", "338310430", "339300249", "436040285", "429760927", "339680052", "433790769", "437570589", "430930244", "435860307", "338300958", "429480113", "431810495", "434090394", "338470074", "428730762", "430130411", "435400002", "458210924", "436160661", "433510067", "442410556", "435700142", "435950954", "338850319", "432070884", "428640803", "436080612", "430280930", "544050615", "428750768", "435990454", "435400675", "435320025", "339640144", "338840914", "435210911", "433900704", "437710541", "436820021", "431830412", "428610580", "435950348", "339470276", "429770513", "434990084", "431850612", "339450569", "857120455", "430230364", "338860009", "458750663", "387870343", "437250126", "437730078", "434230621", "514020580", "432180969", "857140891", "856900329", "438387961", "444270011", "436270539", "339420024", "435770681", "339450932", "435660465", "435950793", "430970639", "438070708", "435770569", "431570918", "434560147", "436170751", "433900086", "436260471", "339830859", "435180384", "435830555", "338430436", "442650540", "435220774", "338440825", "438670742", "428670721", "436080617", "444110779", "432490245", "514250393", "338340360", "435430536", "430070592", "429360199", "339310859", "338290688", "430140922", "338830053", "431560136", "446540890", "434860856", "436040988", "430750994", "514000517", "338450894", "437400231", "430650797", "437800010", "434980030", "339980325", "516640716", "430350028", "435330236", "339470724", "437280200", "895780117", "435570590", "434030459", "436090296", "339460365", "544250710", "437520120", "338570793", "378320910", "433540119", "430920080", "431540523", "435830347", "434160835", "434500357", "435820908", "430730729", "432020142", "435970262", "895880862", "433990081", "429480092", "429240724", "430720864", "434760601", "431210253", "428130228", "434659743", "437790124", "339680342", "514288757", "338710224", "430350671", "431770997", "435390046", "434450710", "433980152", "435380776", "338630838", "437480152", "338820127", "431940173", "430870432", "437480146", "437160262", "433670146", "436220750", "434790025", "433660540", "431270631", "430770068", "435960622", "435850815", "434820704", "435830453", "431170620", "339770437", "378340801", "437500204", "446360849", "434340348", "431240363", "339110294", "435134580", "429770919", "434940238", "339950357", "339770173", "339700787", "435800363", "437620076", "436090085", "430580525", "432440595", "431350669", "437410001", "434780145", "458380537", "431610972", "430670629", "435690513", "339680327", "434880995", "431620764", "339610692", "432190100", "428610855", "435500899", "629710232", "544200285", "436120601", "339580121", "431080454", "431150736", "435960296", "432200567", "437220902"]
}
}]
}
}
}

Response Body:

{
"count": 10001,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
}
}

Above Request body will contain 10,000 empCodes, but due to space constraint I deleted some of them, so I should get count as 10,000, instead I am getting 10,001.

Kindly let me know where is the mistake.

Thanks,
Ram Prasad G

sorry for the huge request body, I just wanted to post you as it is. Please excuse me.

Could it be that u have the same thing twice? so it counts it one more time? u sure u have 10k in 0?

Sorry I didn't understand what you are saying, but I can say that, If we are searching for 10k records, count should return 10k, but its returning 10,001 as count.

Sry, my English sucks when wrtting. I'm saying could it be that u fu'ke' up and inserted 10001 records. Because u didnt limit ur search on 10k, there could be more records, my guess.

It's one record(myv header went into the DB), must be there for sure :smiley:

1 Like

Hi Kevin,

On this I tried with search api query, no.of resulted documents are 10k, but the total is showing 10,001 as output. Problem is only with total field inside hits object.

What gives:

GET thr/thrtype/_count
GET /_cat/indices/thr?v

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