# Count api not giving the consistent result for different datatypes

**URL:** <https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177>\
**Category:** Elasticsearch\
**Created:** [March 30, 2012, 12:13pm UTC](https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177 "2012-03-30T12:13:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [March 30, 2012, 12:13pm UTC](https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177/1 "2012-03-30T12:13:37Z")

</div>

Hi there,  
I need to use the count api for counting the document. and its  
giving me the correct results if the use the string field in query. but if  
i query in the numeric field, its giving 0 count always although, the  
document count is not zero.

for example :

and two type of docs are

type :A  
{  
"title": "abc",  
"state\_guid": 15678}

type:B  
{  
name:"xyz",  
state\_guid: 15678}

if the query is this:  
{"query":  
{"term":  
{state\_guid:"15678"  
}  
}  
}

so if the query is run on the type A, its giving correct count results ,  
but zero in case of type: B  
Can anyone please explain this and if possible please give the solution  
without reindexing the data

---

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [March 30, 2012, 1:04pm UTC](https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177/2 "2012-03-30T13:04:47Z")

</div>

On Friday, March 30, 2012 5:43:37 PM UTC+5:30, Narinder Kaur wrote:

> Hi there,  
> I need to use the count api for counting the document. and its  
> giving me the correct results if the use the string field in query. but if  
> i query in the numeric field, its giving 0 count always although, the  
> document count is not zero.
> 
> for example :
> 
> and two type of docs are
> 
> type :A  
> {  
> "title": "abc",  
> "state\_guid": 15678}
> 
> type:B  
> {  
> name:"xyz",  
> state\_guid: "15678"}
> 
> if the query is this:  
> {"query":  
> {"term":  
> {state\_guid:"15678"  
> }  
> }  
> }
> 
> so if the query is run on the type A, its giving correct count results ,  
> but zero in case of type: B  
> Can anyone please explain this and if possible please give the solution  
> without reindexing the data

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 31, 2012, 8:51pm UTC](https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177/3 "2012-03-31T20:51:47Z")

</div>

- Are you sure both types are marked as numeric? Can you do get mapping and  
verify?

- Are you executing the search explicitly against the type?

On Fri, Mar 30, 2012 at 3:13 PM, Narinder Kaur [narinder.kaur@izap.in](mailto:narinder.kaur@izap.in)wrote:

> Hi there,  
> I need to use the count api for counting the document. and its  
> giving me the correct results if the use the string field in query. but if  
> i query in the numeric field, its giving 0 count always although, the  
> document count is not zero.
> 
> for example :
> 
> and two type of docs are
> 
> type :A  
> {  
> "title": "abc",  
> "state\_guid": 15678}
> 
> type:B  
> {  
> name:"xyz",  
> state\_guid: 15678}
> 
> if the query is this:  
> {"query":  
> {"term":  
> {state\_guid:"15678"  
> }  
> }  
> }
> 
> so if the query is run on the type A, its giving correct count results ,  
> but zero in case of type: B  
> Can anyone please explain this and if possible please give the solution  
> without reindexing the data

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:34am UTC](https://discuss.elastic.co/t/count-api-not-giving-the-consistent-result-for-different-datatypes/7177/4 "2017-07-06T03:34:04Z")

</div>

Closed on July 6, 2017, 3:34am UTC


