# How to filter a value from multivalue field in Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-filter-a-value-from-multivalue-field-in-elasticsearch/16498>\
**Category:** Elasticsearch\
**Created:** [March 20, 2014, 1:06pm UTC](https://discuss.elastic.co/t/how-to-filter-a-value-from-multivalue-field-in-elasticsearch/16498 "2014-03-20T13:06:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anurag\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Anurag\_Tripathi](https://discuss.elastic.co/u/Anurag_Tripathi)\
**Post date:** [March 20, 2014, 1:06pm UTC](https://discuss.elastic.co/t/how-to-filter-a-value-from-multivalue-field-in-elasticsearch/16498/1 "2014-03-20T13:06:10Z")

</div>

Hi, I have a document indexed in this format.

"hits": [  
{  
"\_index": "temp",  
"\_type": "test",  
"\_source": {  
"brand": [  
"A",  
"B",  
"C",  
"D",  
"E",  
"F",  
"G"  
],  
"search\_term": "",  
"age": "19-35 Years",  
"dob": "1981-06-01T00:00:00.000Z",  
"deal": [  
"P",  
"Q",  
"R",  
"S",  
]  
}  
}

I want to extract information related to "brand" : "C".I applied a term  
filter on the created alias but It's not giving me the particular  
value,however it gives me all the values (brand :  
"A","B","C","D","E","F","G".Any trick to get "C" and all the values related  
to "C" ? Here is the term filter which I am applying.Not sure,If I have to  
apply a custom CSV analyzer ?

POST /\_aliases  
{  
"actions" : [  
{  
"add" : {  
"index" : "temp",  
"alias" : "temp\_alias",  
"filter" : {  
"or" : [  
{  
"term" : { "brand" : "C" }  
}  
]  
}  
}  
}  
]  
}

brand and deal are having this mapping.

"brand": { "type": "string", "index": "not\_analyzed" }

Thanks,

Anurag

--  
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/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 31, 2014, 7:17am UTC](https://discuss.elastic.co/t/how-to-filter-a-value-from-multivalue-field-in-elasticsearch/16498/2 "2014-03-31T07:17:39Z")

</div>

Hey,

the filter you applied returns all documents which contain "C" in the brand  
field. This is the expected behaviour. Elasticsearch does not modify the  
original document before it is being returned, so it also contains the  
other values. The term filter is just about inclusion/exclusion of your  
documents beign returned for that alias.

Hope it makes sense.

--Alex

On Thu, Mar 20, 2014 at 2:06 PM, Anurag Tripathi [anurag014@gmail.com](mailto:anurag014@gmail.com)wrote:

> Hi, I have a document indexed in this format.
> 
> "hits": [  
> {  
> "\_index": "temp",  
> "\_type": "test",  
> "\_source": {  
> "brand": [  
> "A",  
> "B",  
> "C",  
> "D",  
> "E",  
> "F",  
> "G"  
> ],  
> "search\_term": "",  
> "age": "19-35 Years",  
> "dob": "1981-06-01T00:00:00.000Z",  
> "deal": [  
> "P",  
> "Q",  
> "R",  
> "S",  
> ]  
> }  
> }
> 
> I want to extract information related to "brand" : "C".I applied a term  
> filter on the created alias but It's not giving me the particular  
> value,however it gives me all the values (brand :  
> "A","B","C","D","E","F","G".Any trick to get "C" and all the values related  
> to "C" ? Here is the term filter which I am applying.Not sure,If I have to  
> apply a custom CSV analyzer ?
> 
> POST /\_aliases  
> {  
> "actions" : [  
> {  
> "add" : {  
> "index" : "temp",  
> "alias" : "temp\_alias",  
> "filter" : {  
> "or" : [  
> {  
> "term" : { "brand" : "C" }  
> }  
> ]  
> }  
> }  
> }  
> ]  
> }
> 
> brand and deal are having this mapping.
> 
> "brand": { "type": "string", "index": "not\_analyzed" }
> 
> Thanks,
> 
> Anurag
> 
> --  
> 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/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f62d1ac3-0614-4034-a664-eab868cb1fd7%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGCwEM\_2hx\_1uHQRcAXFZT-Y\_%3DadrHc%2BtfE8fQD%2BwmUO-V4umA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_2hx_1uHQRcAXFZT-Y_%3DadrHc%2BtfE8fQD%2BwmUO-V4umA%40mail.gmail.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:39am UTC](https://discuss.elastic.co/t/how-to-filter-a-value-from-multivalue-field-in-elasticsearch/16498/3 "2017-07-06T01:39:32Z")

</div>


