# Facet in Array Field

**URL:** <https://discuss.elastic.co/t/facet-in-array-field/8835>\
**Category:** Elasticsearch\
**Created:** [August 23, 2012, 5:59pm UTC](https://discuss.elastic.co/t/facet-in-array-field/8835 "2012-08-23T17:59:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibin](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@vibin](https://discuss.elastic.co/u/vibin)\
**Post date:** [August 23, 2012, 5:59pm UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/1 "2012-08-23T17:59:45Z")

</div>

Hi All,

I am using ElasticSearch v19.1, I am not able to get the exact facet  
result in array field faceting, for Example.

I have an Array Field with values say,

array ["aaa","bbb","ccc"] - is a not analyzed field

When applying Facet for this field with term filter as "aaa" (to select  
facet for 'aaa'), I am getting the following result

aaa - count 1

bbb - count 1

ccc - count 1

I am expecting result as

aaa - count 1

Is it how the facet in Array field works?

Can any one help me on this issue?

Thanks,  
-Vibin

--

---

<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:** [August 23, 2012, 6:02pm UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/2 "2012-08-23T18:02:58Z")

</div>

How did you apply your filter on facet? Could you gist your case?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 août 2012 à 19:59, vibin [vibindhas@gmail.com](mailto:vibindhas@gmail.com) a écrit :

Hi All,

I am using ElasticSearch v19.1, I am not able to get the exact facet result in array field faceting, for Example.

I have an Array Field with values say,

array ["aaa","bbb","ccc"] - is a not analyzed field

When applying Facet for this field with term filter as "aaa" (to select facet for 'aaa'), I am getting the following result

aaa - count 1

bbb - count 1

ccc - count 1

I am expecting result as

aaa - count 1

Is it how the facet in Array field works?

Can any one help me on this issue?

Thanks,  
-Vibin

--

--

---

<div class="post-metadata">

**Author:** ![vibin](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@vibin](https://discuss.elastic.co/u/vibin)\
**Post date:** [September 3, 2012, 5:08am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/3 "2012-09-03T05:08:42Z")

</div>

Hi Pilato,

I have uploaded my case in gist

> <https://gist.github.com/vibindhas/3606794>

Thanks,  
-Vibin

On Thursday, August 23, 2012 11:32:58 PM UTC+5:30, David Pilato wrote:

> How did you apply your filter on facet? Could you gist your case?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 23 août 2012 à 19:59, vibin \<[vibi...@gmail.com](mailto:vibi...@gmail.com) \<javascript:\>\> a écrit :
> 
> Hi All,
> 
> I am using Elasticsearch v19.1, I am not able to get the exact facet  
> result in array field faceting, for Example.
> 
> I have an Array Field with values say,
> 
> array ["aaa","bbb","ccc"] - is a not analyzed field
> 
> When applying Facet for this field with term filter as "aaa" (to select  
> facet for 'aaa'), I am getting the following result
> 
> aaa - count 1
> 
> bbb - count 1
> 
> ccc - count 1
> 
> I am expecting result as
> 
> aaa - count 1
> 
> Is it how the facet in Array field works?
> 
> Can any one help me on this issue?
> 
> Thanks,  
> -Vibin
> 
> --

--

---

<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:** [September 3, 2012, 7:37am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/4 "2012-09-03T07:37:51Z")

</div>

When you gist a case, it should be complete as anybody can reproduce it in some  
minutes.  
See help guide here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)  
[http://www.elasticsearch.org/help/](http://www.elasticsearch.org/help/)

That said, I'm wondering if you are not looking for filter facet:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)

It's hard to understand your you use case without indexed documents.

David.

Le 3 septembre 2012 à 07:08, vibin [vibindhas@gmail.com](mailto:vibindhas@gmail.com) a écrit :

> Hi Pilato,
> 
> I have uploaded my case in gist
> 
> [facet filter for multi array field · GitHub](https://gist.github.com/3606794)
> 
> Thanks,  
> -Vibin
> 
> On Thursday, August 23, 2012 11:32:58 PM UTC+5:30, David Pilato wrote:
> 
> > > How did you apply your filter on facet? Could you gist your case?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 23 août 2012 à 19:59, vibin \< [vibi...@gmail.com](mailto:vibi...@gmail.com)\> a écrit :
> > 
> > Hi All,
> > 
> > ```
> > I am using ElasticSearch v19.1, I am not able to get the exact facet
> > 
> > ```
> > 
> > result in array field faceting, for Example.
> > 
> > ```
> > I have an Array Field with values say,
> > 
> > array ["aaa","bbb","ccc"] - is a not analyzed field
> > 
> > ```
> > 
> > When applying Facet for this field with term filter as "aaa" (to select  
> > facet for 'aaa'), I am getting the following result
> > 
> > aaa - count 1
> > 
> > bbb - count 1
> > 
> > ccc - count 1
> > 
> > I am expecting result as
> > 
> > ```
> > aaa - count 1
> > 
> > ```
> > 
> > Is it how the facet in Array field works?
> > 
> > Can any one help me on this issue?
> > 
> > Thanks,  
> > -Vibin
> > 
> > --
> > 
> > >
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Suraj](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Suraj](https://discuss.elastic.co/u/Suraj)\
**Post date:** [September 3, 2012, 8:32am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/5 "2012-09-03T08:32:15Z")

</div>

Hi Guys,

I have the same kind of problem. I have a gist which you guys can have look:

[https://gist.github.com/3607876](https://gist.github.com/3607876)

// Results:  
facets: {  
participating-org.name: {  
\_type: "terms"  
missing: 0  
total: 8  
other: 0  
terms: [  
{  
term: "def"  
count: 4  
}  
{  
term: "abc"  
count: 4  
}  
]  
}  
}

Actually, here the "def" participating-org has "leading" role. I don't know  
why there is count for "abc" participating-org too which is not in  
"leading" role.

Do you guys have any suggestions? Is it my mappings or the query problems?

Cheers!  
Suraj

On Thursday, August 23, 2012 11:44:45 PM UTC+5:45, vibin wrote:

> Hi All,
> 
> I am using Elasticsearch v19.1, I am not able to get the exact facet  
> result in array field faceting, for Example.
> 
> I have an Array Field with values say,
> 
> array ["aaa","bbb","ccc"] - is a not analyzed field
> 
> When applying Facet for this field with term filter as "aaa" (to select  
> facet for 'aaa'), I am getting the following result
> 
> aaa - count 1
> 
> bbb - count 1
> 
> ccc - count 1
> 
> I am expecting result as
> 
> aaa - count 1
> 
> Is it how the facet in Array field works?
> 
> Can any one help me on this issue?
> 
> Thanks,  
> -Vibin

--

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [September 3, 2012, 11:10am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/6 "2012-09-03T11:10:25Z")

</div>

Hi,

U probably need to use filter within facet.

curl -XPOST 'localhost:9200/org/\_search?pretty=true' -d '{  
"size": 0,  
"facets": {  
"organization\_facets": {  
"terms": {  
"field": "participating-org.name"  
},  
"filter": {  
"term": {  
"participating-org.role": "leading"  
}  
}  
}  
}  
}'

-Sujoy.

On Monday, September 3, 2012 2:02:15 PM UTC+5:30, Suraj Tamang wrote:

> Hi Guys,
> 
> I have the same kind of problem. I have a gist which you guys can have  
> look:
> 
> [https://gist.github.com/3607876](https://gist.github.com/3607876)
> 
> // Results:  
> facets: {  
> participating-org.name: {  
> \_type: "terms"  
> missing: 0  
> total: 8  
> other: 0  
> terms: [  
> {  
> term: "def"  
> count: 4  
> }  
> {  
> term: "abc"  
> count: 4  
> }  
> ]  
> }  
> }
> 
> Actually, here the "def" participating-org has "leading" role. I don't  
> know why there is count for "abc" participating-org too which is not in  
> "leading" role.
> 
> Do you guys have any suggestions? Is it my mappings or the query problems?
> 
> Cheers!  
> Suraj
> 
> On Thursday, August 23, 2012 11:44:45 PM UTC+5:45, vibin wrote:
> 
> > Hi All,
> > 
> > I am using Elasticsearch v19.1, I am not able to get the exact facet  
> > result in array field faceting, for Example.
> > 
> > I have an Array Field with values say,
> > 
> > array ["aaa","bbb","ccc"] - is a not analyzed field
> > 
> > When applying Facet for this field with term filter as "aaa" (to select  
> > facet for 'aaa'), I am getting the following result
> > 
> > aaa - count 1
> > 
> > bbb - count 1
> > 
> > ccc - count 1
> > 
> > I am expecting result as
> > 
> > aaa - count 1
> > 
> > Is it how the facet in Array field works?
> > 
> > Can any one help me on this issue?
> > 
> > Thanks,  
> > -Vibin

--

---

<div class="post-metadata">

**Author:** ![Suraj](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Suraj](https://discuss.elastic.co/u/Suraj)\
**Post date:** [September 3, 2012, 4:21pm UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/7 "2012-09-03T16:21:21Z")

</div>

Hi Sujoy,

I have done exactly what you have written, but again, it does not give the  
participating-org.name with facet counts. If there is anything missing, you  
can add it.

#suraz

On Monday, September 3, 2012 4:55:25 PM UTC+5:45, Sujoy Sett wrote:

> Hi,

> U probably need to use filter within facet.
> 
> curl -XPOST 'localhost:9200/org/\_search?pretty=true' -d '{  
> "size": 0,  
> "facets": {  
> "organization\_facets": {  
> "terms": {  
> "field": "participating-org.name"  
> },  
> "filter": {  
> "term": {  
> "participating-org.role": "leading"  
> }  
> }  
> }  
> }  
> }'
> 
> -Sujoy.
> 
> On Monday, September 3, 2012 2:02:15 PM UTC+5:30, Suraj Tamang wrote:
> 
> > Hi Guys,
> > 
> > I have the same kind of problem. I have a gist which you guys can have  
> > look:
> > 
> > [https://gist.github.com/3607876](https://gist.github.com/3607876)
> > 
> > // Results:  
> > facets: {  
> > participating-org.name: {  
> > \_type: "terms"  
> > missing: 0  
> > total: 8  
> > other: 0  
> > terms: [  
> > {  
> > term: "def"  
> > count: 4  
> > }  
> > {  
> > term: "abc"  
> > count: 4  
> > }  
> > ]  
> > }  
> > }
> > 
> > Actually, here the "def" participating-org has "leading" role. I don't  
> > know why there is count for "abc" participating-org too which is not in  
> > "leading" role.
> > 
> > Do you guys have any suggestions? Is it my mappings or the query problems?
> > 
> > Cheers!  
> > Suraj
> > 
> > On Thursday, August 23, 2012 11:44:45 PM UTC+5:45, vibin wrote:
> > 
> > > Hi All,
> > > 
> > > I am using Elasticsearch v19.1, I am not able to get the exact facet  
> > > result in array field faceting, for Example.
> > > 
> > > I have an Array Field with values say,
> > > 
> > > array ["aaa","bbb","ccc"] - is a not analyzed field
> > > 
> > > When applying Facet for this field with term filter as "aaa" (to select  
> > > facet for 'aaa'), I am getting the following result
> > > 
> > > aaa - count 1
> > > 
> > > bbb - count 1
> > > 
> > > ccc - count 1
> > > 
> > > I am expecting result as
> > > 
> > > aaa - count 1
> > > 
> > > Is it how the facet in Array field works?
> > > 
> > > Can any one help me on this issue?
> > > 
> > > Thanks,  
> > > -Vibin

--

---

<div class="post-metadata">

**Author:** ![Suraj](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Suraj](https://discuss.elastic.co/u/Suraj)\
**Post date:** [September 4, 2012, 4:44am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/8 "2012-09-04T04:44:18Z")

</div>

Hi everyone,

I got my answer from stackoverflow post:

> <https://stackoverflow.com/questions/8507489/i-cant-seem-to-get-faceted-search-working-in-elastic-search>

And My Complete Gist with Solution: [https://gist.github.com/3616612](https://gist.github.com/3616612)

#suraz

On Monday, September 3, 2012 10:06:21 PM UTC+5:45, Suraj Tamang wrote:

> Hi Sujoy,
> 
> I have done exactly what you have written, but again, it does not give the  
> participating-org.name with facet counts. If there is anything missing,  
> you can add it.
> 
> #suraz
> 
> On Monday, September 3, 2012 4:55:25 PM UTC+5:45, Sujoy Sett wrote:
> 
> > Hi,
> 
> > U probably need to use filter within facet.
> > 
> > curl -XPOST 'localhost:9200/org/\_search?pretty=true' -d '{  
> > "size": 0,  
> > "facets": {  
> > "organization\_facets": {  
> > "terms": {  
> > "field": "participating-org.name"  
> > },  
> > "filter": {  
> > "term": {  
> > "participating-org.role": "leading"  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > -Sujoy.
> > 
> > On Monday, September 3, 2012 2:02:15 PM UTC+5:30, Suraj Tamang wrote:
> > 
> > > Hi Guys,
> > > 
> > > I have the same kind of problem. I have a gist which you guys can have  
> > > look:
> > > 
> > > [https://gist.github.com/3607876](https://gist.github.com/3607876)
> > > 
> > > // Results:  
> > > facets: {  
> > > participating-org.name: {  
> > > \_type: "terms"  
> > > missing: 0  
> > > total: 8  
> > > other: 0  
> > > terms: [  
> > > {  
> > > term: "def"  
> > > count: 4  
> > > }  
> > > {  
> > > term: "abc"  
> > > count: 4  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > Actually, here the "def" participating-org has "leading" role. I don't  
> > > know why there is count for "abc" participating-org too which is not in  
> > > "leading" role.
> > > 
> > > Do you guys have any suggestions? Is it my mappings or the query  
> > > problems?
> > > 
> > > Cheers!  
> > > Suraj
> > > 
> > > On Thursday, August 23, 2012 11:44:45 PM UTC+5:45, vibin wrote:
> > > 
> > > > Hi All,
> > > > 
> > > > I am using Elasticsearch v19.1, I am not able to get the exact facet  
> > > > result in array field faceting, for Example.
> > > > 
> > > > I have an Array Field with values say,
> > > > 
> > > > array ["aaa","bbb","ccc"] - is a not analyzed field
> > > > 
> > > > When applying Facet for this field with term filter as "aaa" (to select  
> > > > facet for 'aaa'), I am getting the following result
> > > > 
> > > > aaa - count 1
> > > > 
> > > > bbb - count 1
> > > > 
> > > > ccc - count 1
> > > > 
> > > > I am expecting result as
> > > > 
> > > > aaa - count 1
> > > > 
> > > > Is it how the facet in Array field works?
> > > > 
> > > > Can any one help me on this issue?
> > > > 
> > > > Thanks,  
> > > > -Vibin

--

---

<div class="post-metadata">

**Author:** ![Mandar\_Rahurkar](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mandar\_Rahurkar](https://discuss.elastic.co/u/Mandar_Rahurkar)\
**Post date:** [April 9, 2014, 6:30am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/9 "2014-04-09T06:30:31Z")

</div>

I tried executing this example from google which an user was able to run:

[https://gist.github.com/surajtamang/3616612](https://gist.github.com/surajtamang/3616612)  
However, my output was:

[https://gist.github.com/rahurkar/10231685](https://gist.github.com/rahurkar/10231685)

with no output for facets.

Did this functionality break or change from what's described in the  
documentation?

-Mandar

On Monday, September 3, 2012 9:44:18 PM UTC-7, suraz wrote:

> Hi everyone,
> 
> I got my answer from stackoverflow post:  
> [elasticsearch - I can't seem to get faceted search working in elastic search - Stack Overflow](http://stackoverflow.com/questions/8507489/i-cant-seem-to-get-faceted-search-working-in-elastic-search)
> 
> And My Complete Gist with Solution: [https://gist.github.com/3616612](https://gist.github.com/3616612)
> 
> #suraz
> 
> On Monday, September 3, 2012 10:06:21 PM UTC+5:45, Suraj Tamang wrote:
> 
> > Hi Sujoy,
> > 
> > I have done exactly what you have written, but again, it does not give  
> > the participating-org.name with facet counts. If there is anything  
> > missing, you can add it.
> > 
> > #suraz
> > 
> > On Monday, September 3, 2012 4:55:25 PM UTC+5:45, Sujoy Sett wrote:
> > 
> > > Hi,
> > 
> > > U probably need to use filter within facet.
> > > 
> > > curl -XPOST 'localhost:9200/org/\_search?pretty=true' -d '{  
> > > "size": 0,  
> > > "facets": {  
> > > "organization\_facets": {  
> > > "terms": {  
> > > "field": "participating-org.name"  
> > > },  
> > > "filter": {  
> > > "term": {  
> > > "participating-org.role": "leading"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }'
> > > 
> > > -Sujoy.
> > > 
> > > On Monday, September 3, 2012 2:02:15 PM UTC+5:30, Suraj Tamang wrote:
> > > 
> > > > Hi Guys,
> > > > 
> > > > I have the same kind of problem. I have a gist which you guys can have  
> > > > look:
> > > > 
> > > > [https://gist.github.com/3607876](https://gist.github.com/3607876)
> > > > 
> > > > // Results:  
> > > > facets: {  
> > > > participating-org.name: {  
> > > > \_type: "terms"  
> > > > missing: 0  
> > > > total: 8  
> > > > other: 0  
> > > > terms: [  
> > > > {  
> > > > term: "def"  
> > > > count: 4  
> > > > }  
> > > > {  
> > > > term: "abc"  
> > > > count: 4  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> > > > 
> > > > Actually, here the "def" participating-org has "leading" role. I don't  
> > > > know why there is count for "abc" participating-org too which is not in  
> > > > "leading" role.
> > > > 
> > > > Do you guys have any suggestions? Is it my mappings or the query  
> > > > problems?
> > > > 
> > > > Cheers!  
> > > > Suraj
> > > > 
> > > > On Thursday, August 23, 2012 11:44:45 PM UTC+5:45, vibin wrote:
> > > > 
> > > > > Hi All,
> > > > > 
> > > > > I am using Elasticsearch v19.1, I am not able to get the exact facet  
> > > > > result in array field faceting, for Example.
> > > > > 
> > > > > I have an Array Field with values say,
> > > > > 
> > > > > array ["aaa","bbb","ccc"] - is a not analyzed field
> > > > > 
> > > > > When applying Facet for this field with term filter as "aaa" (to  
> > > > > select facet for 'aaa'), I am getting the following result
> > > > > 
> > > > > aaa - count 1
> > > > > 
> > > > > bbb - count 1
> > > > > 
> > > > > ccc - count 1
> > > > > 
> > > > > I am expecting result as
> > > > > 
> > > > > aaa - count 1
> > > > > 
> > > > > Is it how the facet in Array field works?
> > > > > 
> > > > > Can any one help me on this issue?
> > > > > 
> > > > > Thanks,  
> > > > > -Vibin

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e35df782-4414-499f-a7fa-9c2ccf1acacb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e35df782-4414-499f-a7fa-9c2ccf1acacb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:37am UTC](https://discuss.elastic.co/t/facet-in-array-field/8835/10 "2017-07-06T01:37:26Z")

</div>


