# Terms facet : bad results or misunderstanding?

**URL:** https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616
**Category:** Elasticsearch
**Created:** [June 14, 2011, 12:02pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616 "2011-06-14T12:02:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 14, 2011, 12:02pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/1 "2011-06-14T12:02:59Z")

</div>

Hi,

While I was creating a test case for this thread : [http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html](http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html), I saw something that looks wrong (or I didn't understood how terms facet works).

Here is a Gist : [https://gist.github.com/1024756](https://gist.github.com/1024756)

My facet should return something like :  
"facets" : {  
"f\_tags" : {  
"\_type" : "terms",  
"missing" : 0,  
"terms" : [ {  
"term" : "seven",  
"count" : 7  
}, {  
"term" : "six",  
"count" : 6  
}, {  
"term" : "five",  
"count" : 5  
}, {  
"term" : "four",  
"count" : 4  
}, {  
"term" : "three",  
"count" : 3  
} ]  
}

But, I got this :  
"facets" : {  
"f\_tags" : {  
"\_type" : "terms",  
"missing" : 0,  
"terms" : [ {  
"term" : "seven",  
"count" : 7  
}, {  
"term" : "six",  
"count" : 6  
}, {  
"term" : "three",  
"count" : 3  
}, {  
"term" : "four",  
"count" : 3  
}, {  
"term" : "five",  
"count" : 3  
} ]  
}

As you can see, the 3 last terms seems to be wrong...

Am I doing something wrong ?

Thanks for any help  
David.

---

<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: [June 14, 2011, 3:53pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/2 "2011-06-14T15:53:56Z")

</div>

I am getting the correct counts with the gist you provided. Are you executing it as a single script? Maybe the last bits are not refreshed yet? Or maybe are you specifying in your test a different size for the facets?

On Tuesday, June 14, 2011 at 3:02 PM, David Pilato wrote:

> Hi,
> 
> While I was creating a test case for this thread : [http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html](http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html), I saw something that looks wrong (or I didn't understood how terms facet works).
> 
> Here is a Gist : [ES Terms Facet send back bad count results · GitHub](https://gist.github.com/1024756)
> 
> My facet should return something like :  
> "facets" : {  
> "f\_tags" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "terms" : [ {  
> "term" : "seven",  
> "count" : 7  
> }, {  
> "term" : "six",  
> "count" : 6  
> }, {  
> "term" : "five",  
> "count" : 5  
> }, {  
> "term" : "four",  
> "count" : 4  
> }, {  
> "term" : "three",  
> "count" : 3  
> } ]  
> }
> 
> But, I got this :  
> "facets" : {  
> "f\_tags" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "terms" : [ {  
> "term" : "seven",  
> "count" : 7  
> }, {  
> "term" : "six",  
> "count" : 6  
> }, {  
> "term" : "three",  
> "count" : 3  
> }, {  
> "term" : "four",  
> "count" : 3  
> }, {  
> "term" : "five",  
> "count" : 3  
> } ]  
> }
> 
> As you can see, the 3 last terms seems to be wrong...
> 
> Am I doing something wrong ?
> 
> Thanks for any help  
> David.

---

<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: [June 14, 2011, 3:55pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/3 "2011-06-14T15:55:20Z")

</div>

Sorry, I now see in the response that it did "see" 7 docs, so, its strange. Is the gist exactly what you are executing?

On Tuesday, June 14, 2011 at 6:53 PM, Shay Banon wrote:

> I am getting the correct counts with the gist you provided. Are you executing it as a single script? Maybe the last bits are not refreshed yet? Or maybe are you specifying in your test a different size for the facets?
> 
> On Tuesday, June 14, 2011 at 3:02 PM, David Pilato wrote:
> 
> > Hi,
> > 
> > While I was creating a test case for this thread : [http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html](http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html), I saw something that looks wrong (or I didn't understood how terms facet works).
> > 
> > Here is a Gist : [ES Terms Facet send back bad count results · GitHub](https://gist.github.com/1024756)
> > 
> > My facet should return something like :  
> > "facets" : {  
> > "f\_tags" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "terms" : [ {  
> > "term" : "seven",  
> > "count" : 7  
> > }, {  
> > "term" : "six",  
> > "count" : 6  
> > }, {  
> > "term" : "five",  
> > "count" : 5  
> > }, {  
> > "term" : "four",  
> > "count" : 4  
> > }, {  
> > "term" : "three",  
> > "count" : 3  
> > } ]  
> > }
> > 
> > But, I got this :  
> > "facets" : {  
> > "f\_tags" : {  
> > "\_type" : "terms",  
> > "missing" : 0,  
> > "terms" : [ {  
> > "term" : "seven",  
> > "count" : 7  
> > }, {  
> > "term" : "six",  
> > "count" : 6  
> > }, {  
> > "term" : "three",  
> > "count" : 3  
> > }, {  
> > "term" : "four",  
> > "count" : 3  
> > }, {  
> > "term" : "five",  
> > "count" : 3  
> > } ]  
> > }
> > 
> > As you can see, the 3 last terms seems to be wrong...
> > 
> > Am I doing something wrong ?
> > 
> > Thanks for any help  
> > David.

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [June 14, 2011, 4:04pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/4 "2011-06-14T16:04:00Z")

</div>

On Tue, 2011-06-14 at 18:55 +0300, Shay Banon wrote:

> Sorry, I now see in the response that it did "see" 7 docs, so, its  
> strange. Is the gist exactly what you are executing?

I tried the same gist on 0.16.2 and got the correct counts, but then  
also had missing: 7

clint

---

<div class="post-metadata">

### Author: ![dpilato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpilato/32/2449_2.png) [@dpilato](https://discuss.elastic.co/u/dpilato)
#### Post date: [June 15, 2011, 1:05pm UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/5 "2011-06-15T13:05:45Z")

</div>

My bad !

I don't know why but after deleting the index curl -X DELETE "[http://localhost:9200/articles](http://localhost:9200/articles)"  
and then creating articles, everything is now correct.

Sorry to have raised a fake bug !

Thanks for having take time looking at it.  
Cheers

---

<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, 4:03am UTC](https://discuss.elastic.co/t/terms-facet-bad-results-or-misunderstanding/4616/6 "2017-07-06T04:03:28Z")

</div>


