# Filter search by a value in a array

**URL:** <https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217>\
**Category:** Elasticsearch\
**Created:** [March 7, 2014, 5:18am UTC](https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217 "2014-03-07T05:18:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dashaus](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@dashaus](https://discuss.elastic.co/u/dashaus)\
**Post date:** [March 7, 2014, 5:18am UTC](https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217/1 "2014-03-07T05:18:18Z")

</div>

HI!  
I want filter my search by a value in a array. I have this in ES:

{  
"\_id" : "BeyKH2Cx",  
"occupations" : ["d5ot2bwu","HwmXygzK"],  
"name" : "Matthew McConaughey"  
},  
{  
"\_id" : "BeyKH2Cx",  
"occupations" : ["HwmXygzK"],  
"name" : "Matthew Nilan"  
}

And i execute a search as below:

GET mongoindex/professionals/\_search?search\_type=dfs\_query\_and\_fetch  
{

```
"fields" : ["name", "_id","occupations"],

```

"query": {  
"filtered": {  
"query": {  
"multi\_match" : {  
"query" : "stephen",  
"fuzziness": 2,  
"prefix\_length": 1,  
"fields" : ["artname","realname"],  
"analyzer": "simple"  
}  
},  
"filter" : {  
"terms" : {  
"occupations" : ["3qm3LsHP"]  
}  
}  
}  
}  
}

But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put  
"\_id":"BeyKH2Cx" it works, but I need filter by a value in the  
"occupations" array. What is the way to make this work?

Thanks!

Best,  
Emilio

--  
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/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [March 7, 2014, 6:56am UTC](https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217/2 "2014-03-07T06:56:04Z")

</div>

Lowercase your filter as a TermFilter is not analyzed

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

Le 7 mars 2014 à 06:18, Emilio García-Pumarino Álvarez [emili.tfe@gmail.com](mailto:emili.tfe@gmail.com) a écrit :

HI!  
I want filter my search by a value in a array. I have this in ES:  
{  
"\_id" : "BeyKH2Cx",  
"occupations" : ["d5ot2bwu","HwmXygzK"],  
"name" : "Matthew McConaughey"  
},  
{  
"\_id" : "BeyKH2Cx",  
"occupations" : ["HwmXygzK"],  
"name" : "Matthew Nilan"  
}

And i execute a search as below:

GET mongoindex/professionals/\_search?search\_type=dfs\_query\_and\_fetch  
{

```
"fields" : ["name", "_id","occupations"],

```

"query": {  
"filtered": {  
"query": {  
"multi\_match" : {  
"query" : "stephen",  
"fuzziness": 2,  
"prefix\_length": 1,  
"fields" : ["artname","realname"],  
"analyzer": "simple"  
}  
},  
"filter" : {  
"terms" : {  
"occupations" : ["3qm3LsHP"]  
}  
}  
}  
}  
}

But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put "\_id":"BeyKH2Cx" it works, but I need filter by a value in the "occupations" array. What is the way to make this work?

Thanks!

Best,  
Emilio

--  
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/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com).  
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/027C622E-4FCF-4E7C-BC27-2139DB45710A%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/027C622E-4FCF-4E7C-BC27-2139DB45710A%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dashaus](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@dashaus](https://discuss.elastic.co/u/dashaus)\
**Post date:** [March 7, 2014, 5:20pm UTC](https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217/3 "2014-03-07T17:20:58Z")

</div>

Oops! I use instead:  
"filter": {  
"query": {  
"match": {  
"occupations": "3qm3LsHP"  
}  
}  
}

And it works! Thanks for detail.

Best,  
Emilio

El viernes, 7 de marzo de 2014 06:56:04 UTC, David Pilato escribió:

> Lowercase your filter as a TermFilter is not analyzed
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 7 mars 2014 à 06:18, Emilio García-Pumarino Álvarez \<[emil...@gmail.com](mailto:emil...@gmail.com)\<javascript:\>\>  
> a écrit :
> 
> HI!  
> I want filter my search by a value in a array. I have this in ES:
> 
> {  
> "\_id" : "BeyKH2Cx",  
> "occupations" : ["d5ot2bwu","HwmXygzK"],  
> "name" : "Matthew McConaughey"  
> },  
> {  
> "\_id" : "BeyKH2Cx",  
> "occupations" : ["HwmXygzK"],  
> "name" : "Matthew Nilan"  
> }
> 
> And i execute a search as below:
> 
> GET mongoindex/professionals/\_search?search\_type=dfs\_query\_and\_fetch  
> {
> 
> ```
> "fields" : ["name", "_id","occupations"],
> 
> ```
> 
> "query": {  
> "filtered": {  
> "query": {  
> "multi\_match" : {  
> "query" : "stephen",  
> "fuzziness": 2,  
> "prefix\_length": 1,  
> "fields" : ["artname","realname"],  
> "analyzer": "simple"  
> }  
> },  
> "filter" : {  
> "terms" : {  
> "occupations" : ["3qm3LsHP"]  
> }  
> }  
> }  
> }  
> }
> 
> But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put  
> "\_id":"BeyKH2Cx" it works, but I need filter by a value in the  
> "occupations" array. What is the way to make this work?
> 
> Thanks!
> 
> Best,  
> Emilio
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%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/bf24b5d5-29f2-411c-8320-455a0cff3629%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bf24b5d5-29f2-411c-8320-455a0cff3629%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:44am UTC](https://discuss.elastic.co/t/filter-search-by-a-value-in-a-array/16217/4 "2017-07-06T01:44:49Z")

</div>


