# Exact match for a multiple value facet

**URL:** <https://discuss.elastic.co/t/exact-match-for-a-multiple-value-facet/6766>\
**Category:** Elasticsearch\
**Created:** [February 21, 2012, 10:15am UTC](https://discuss.elastic.co/t/exact-match-for-a-multiple-value-facet/6766 "2012-02-21T10:15:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Disneur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_disneur/32/2987_2.png) [@Kevin\_Disneur](https://discuss.elastic.co/u/Kevin_Disneur)\
**Post date:** [February 21, 2012, 10:15am UTC](https://discuss.elastic.co/t/exact-match-for-a-multiple-value-facet/6766/1 "2012-02-21T10:15:51Z")

</div>

Hello,

We're moving our search and faceting solution for our e-commerce  
website from SOLR to elastic search, we're thrilled so far by the  
speed of the solution but we're encountering a problem for which we  
couldn't find a solution in the documentation or on the archives of  
this mailing list.

We have a list of products for which we store multiple values:  
id, color\_id, color\_title, size\_ids, size\_titles

We're using color\_title and size\_titles as Facets. color\_title is a  
unique value facet and size\_titles is multiple.  
Titles are used for sorting and displaying, so we need to be able to  
match ids with values.

For the unique value facet (color) we used a script :

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"color\_title": {  
"terms": {  
"field": "color\_title",  
"script" : "term + ';' + \_source.color\_id"  
}  
}  
}  
}

We tried to use the same principle for sizes but it doesn't work.

For a same term, we get multiple results corresponding to the list of  
all the size\_ids containing our size\_title :

size\_title; [size\_ids]  
47 ;[18, 26, 14, 15, 16, 17, 19, 20]  
47 ;[21, 14, 15, 22, 16, 23, 24, 19, 25, 18, 26, 13, 20]  
47 ;[27, 16, 17, 25, 52, 26, 14]  
48 ;[14, 15, 16, 23, 17, 19, 20, 18, 26, 69]

Is there any way to get the exact size\_id matching our size\_title for  
a multiple value facet?

Thanks in advance for your help and the good work you put into this  
project.

---

<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:** [February 24, 2012, 1:18pm UTC](https://discuss.elastic.co/t/exact-match-for-a-multiple-value-facet/6766/2 "2012-02-24T13:18:39Z")

</div>

First, regarding the first facet, prefer not to use \_source.., since this will cause loading and parsing source for each document matching the query. Prefer doc.

Regarding the second facet, multi values are fine, but getting a "relationship" between multi values is problematic since its not maintained if they exist in the same doc (i.e size\_ids : [1, 2], size\_titles : ["test", "value"]). I didn't full understand why you need a facet that combines the two, why not just use size\_ids?

On Tuesday, February 21, 2012 at 12:15 PM, Kevin Disneur wrote:

> Hello,
> 
> We're moving our search and faceting solution for our e-commerce  
> website from SOLR to Elasticsearch, we're thrilled so far by the  
> speed of the solution but we're encountering a problem for which we  
> couldn't find a solution in the documentation or on the archives of  
> this mailing list.
> 
> We have a list of products for which we store multiple values:  
> id, color\_id, color\_title, size\_ids, size\_titles
> 
> We're using color\_title and size\_titles as Facets. color\_title is a  
> unique value facet and size\_titles is multiple.  
> Titles are used for sorting and displaying, so we need to be able to  
> match ids with values.
> 
> For the unique value facet (color) we used a script :
> 
> {  
> "query": {  
> "match\_all": {}  
> },  
> "facets": {  
> "color\_title": {  
> "terms": {  
> "field": "color\_title",  
> "script" : "term + ';' + \_source.color\_id"  
> }  
> }  
> }  
> }
> 
> We tried to use the same principle for sizes but it doesn't work.
> 
> For a same term, we get multiple results corresponding to the list of  
> all the size\_ids containing our size\_title :
> 
> size\_title; [size\_ids]  
> 47 ;[18, 26, 14, 15, 16, 17, 19, 20]  
> 47 ;[21, 14, 15, 22, 16, 23, 24, 19, 25, 18, 26, 13, 20]  
> 47 ;[27, 16, 17, 25, 52, 26, 14]  
> 48 ;[14, 15, 16, 23, 17, 19, 20, 18, 26, 69]
> 
> Is there any way to get the exact size\_id matching our size\_title for  
> a multiple value facet?
> 
> Thanks in advance for your help and the good work you put into this  
> project.

---

<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:38am UTC](https://discuss.elastic.co/t/exact-match-for-a-multiple-value-facet/6766/3 "2017-07-06T03:38:26Z")

</div>

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


