# Terms facet: does it work when field appears multiple times in the doc?

**URL:** <https://discuss.elastic.co/t/terms-facet-does-it-work-when-field-appears-multiple-times-in-the-doc/5642>\
**Category:** Elasticsearch\
**Created:** [October 19, 2011, 11:03am UTC](https://discuss.elastic.co/t/terms-facet-does-it-work-when-field-appears-multiple-times-in-the-doc/5642 "2011-10-19T11:03:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pedro/32/2564_2.png) [@pedro](https://discuss.elastic.co/u/pedro)\
**Post date:** [October 19, 2011, 11:03am UTC](https://discuss.elastic.co/t/terms-facet-does-it-work-when-field-appears-multiple-times-in-the-doc/5642/1 "2011-10-19T11:03:38Z")

</div>

Hello there.

I'm having a terms facet returning different things than I expected.

My docs have this structure:

{  
{a: { name: "a"}},  
{b: { name: "b"}},  
{c: { name: "c"}},  
{d: { name: "d"}},  
}

, where those a...d vary according to the doc.

When I do a terms facet on "field":"name", appears to me that ES is only  
getting the first term on the doc, cause I get 3 terms while I was  
expecting 166.

Any tips / comments on this? Whenever I have this kind of very dynamic  
mapping I have troubles doing this kind of queries...

Cheers

-pedro

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [October 19, 2011, 8:23pm UTC](https://discuss.elastic.co/t/terms-facet-does-it-work-when-field-appears-multiple-times-in-the-doc/5642/2 "2011-10-19T20:23:09Z")

</div>

are you faceting on a none analyzed field?

"The field used for facet calculations must be of type numeric, date/  
time or analyzed as a single token."

E.g. if you like multiple values for one field you can use an array of  
strings

Peter.

On 19 Okt., 13:03, Pedro Alves [pmgal...@gmail.com](mailto:pmgal...@gmail.com) wrote:

> Hello there.
> 
> I'm having a terms facet returning different things than I expected.
> 
> My docs have this structure:
> 
> {  
> {a: { name: "a"}},  
> {b: { name: "b"}},  
> {c: { name: "c"}},  
> {d: { name: "d"}},
> 
> }
> 
> , where those a...d vary according to the doc.
> 
> When I do a terms facet on "field":"name", appears to me that ES is only  
> getting the first term on the doc, cause I get 3 terms while I was  
> expecting 166.
> 
> Any tips / comments on this? Whenever I have this kind of very dynamic  
> mapping I have troubles doing this kind of queries...
> 
> Cheers
> 
> -pedro

---

<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:51am UTC](https://discuss.elastic.co/t/terms-facet-does-it-work-when-field-appears-multiple-times-in-the-doc/5642/3 "2017-07-06T03:51:23Z")

</div>


