# Need help with filter on array

**URL:** <https://discuss.elastic.co/t/need-help-with-filter-on-array/9850>\
**Category:** Elasticsearch\
**Created:** [November 27, 2012, 7:07pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850 "2012-11-27T19:07:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey/32/2869_2.png) [@Alexey](https://discuss.elastic.co/u/Alexey)\
**Post date:** [November 27, 2012, 7:07pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/1 "2012-11-27T19:07:29Z")

</div>

Hello everyone,

I have a problem with filter queries.

Here is my piece of index:

broadcasting\_regions:  
[

- 

{  
- region:  
{  
- id: 26,  
- name:  
[  
- "enenenen",  
- "rururu"  
]  
},  
- country:  
{  
- id: 0,  
- name: []  
}  
}

],

I'm trying to filter items by 'broadcasting\_regions.region.name' with the  
following curl query:

curl -X GET  
"[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)"  
-d '{"filter":{"terms":{"broadcasting\_regions.region.name":["rururu"]}}}'

Unfortunately I get nothing:

{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

Could you please tell me what's wrong with my query?

--

---

<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:** [November 27, 2012, 7:14pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/2 "2012-11-27T19:14:29Z")

</div>

Try with -XPOST

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

Le 27 nov. 2012 à 20:07, Alexey Astafyev [av.astafyev@gmail.com](mailto:av.astafyev@gmail.com) a écrit :

Hello everyone,

I have a problem with filter queries.

Here is my piece of index:

broadcasting\_regions: [  
{  
region: {  
id: 26,  
name: [  
"enenenen",  
"rururu"  
]  
},  
country: {  
id: 0,  
name: []  
}  
}  
],

I'm trying to filter items by 'broadcasting\_regions.region.name' with the following curl query:

curl -X GET "[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)" -d '{"filter":{"terms":{"broadcasting\_regions.region.name":["rururu"]}}}'

Unfortunately I get nothing:

{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

## Could you please tell me what's wrong with my query?

--

---

<div class="post-metadata">

**Author:** ![Alexey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey/32/2869_2.png) [@Alexey](https://discuss.elastic.co/u/Alexey)\
**Post date:** [November 27, 2012, 7:26pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/3 "2012-11-27T19:26:48Z")

</div>

Sorry, but it doesn't help ☹

I get success with the following attribute and query:

age\_category:  
{

- id: 9,
- name:  
[
  - "age en",
  - "age ru"  
]

}

curl -X GET  
"[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)"  
-d '{"filter":{"terms":{"age\_category.name":["age en"]}}}'

But, when I'm trying to search on array, it fails.

On Tuesday, November 27, 2012 11:14:35 PM UTC+4, David Pilato wrote:

> Try with -XPOST
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 nov. 2012 à 20:07, Alexey Astafyev \<[av.as...@gmail.com](mailto:av.as...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hello everyone,
> 
> I have a problem with filter queries.
> 
> Here is my piece of index:
> 
> broadcasting\_regions:  
> [
> 
> - 
> 
> {  
> - region:  
> {  
> - id: 26,  
> - name:  
> [  
> - "enenenen",  
> - "rururu"  
> ]  
> },  
> - country:  
> {  
> - id: 0,  
> - name:   
> }  
> }
> 
> ],
> 
> I'm trying to filter items by 'broadcasting\_regions.region.name' with the  
> following curl query:
> 
> curl -X GET "  
> [http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)"  
> -d '{"filter":{"terms":{"broadcasting\_regions.region.name":["rururu"]}}}'
> 
> Unfortunately I get nothing:
> 
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> Could you please tell me what's wrong with my query?
> 
> --

--

---

<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:** [November 27, 2012, 7:38pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/4 "2012-11-27T19:38:01Z")

</div>

Then, try to wrap your filter in a FilteredQuery with a MatchAll Query.

That said, you have to use POST. If you don't use it, ES will use URL parameters (q=\* for example).

Best, if you could provide (gist) a full curl recreation, I will try to help you.

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

Le 27 nov. 2012 à 20:26, Alexey Astafyev [av.astafyev@gmail.com](mailto:av.astafyev@gmail.com) a écrit :

> Sorry, but it doesn't help ☹
> 
> I get success with the following attribute and query:
> 
> age\_category: {  
> id: 9,  
> name: [  
> "age en",  
> "age ru"  
> ]  
> }
> 
> curl -X GET "[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)" -d '{"filter":{"terms":{"age\_category.name":["age en"]}}}'
> 
> But, when I'm trying to search on array, it fails.
> 
> On Tuesday, November 27, 2012 11:14:35 PM UTC+4, David Pilato wrote:  
> Try with -XPOST
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 nov. 2012 à 20:07, Alexey Astafyev [av.as...@gmail.com](mailto:av.as...@gmail.com) a écrit :
> 
> Hello everyone,
> 
> I have a problem with filter queries.
> 
> Here is my piece of index:
> 
> broadcasting\_regions:  
> [  
> {  
> region:  
> {  
> id: 26,  
> name:  
> [  
> "enenenen",  
> "rururu"  
> ]  
> },  
> country:  
> {  
> id: 0,  
> name:   
> }  
> }  
> ],
> 
> I'm trying to filter items by 'broadcasting\_regions.region.name' with the following curl query:
> 
> curl -X GET "[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)" -d '{"filter":{"terms":{"broadcasting\_regions.region.name":["rururu"]}}}'
> 
> Unfortunately I get nothing:
> 
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> ## Could you please tell me what's wrong with my query?
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 7:51pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/5 "2012-11-27T19:51:43Z")

</div>

> That said, you have to use POST. If you don't use it, ES will use URL  
> parameters (q=\* for example).

No, you can use GET with /\_search and a body. But some clients (eg  
javascript) don't support that, in which case you can use POST instead.

clint

> 

--

---

<div class="post-metadata">

**Author:** ![Alexey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey/32/2869_2.png) [@Alexey](https://discuss.elastic.co/u/Alexey)\
**Post date:** [November 27, 2012, 8:09pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/6 "2012-11-27T20:09:36Z")

</div>

Thank you David,

FilteredQuery helped me.

> <https://gist.github.com/av-ast/4156678>

--  
Alexey Astafyev  
Sent with Sparrow ([http://www.sparrowmailapp.com/?sig](http://www.sparrowmailapp.com/?sig))

On Tuesday, November 27, 2012 at 11:38 PM, David Pilato wrote:

> Then, try to wrap your filter in a FilteredQuery with a MatchAll Query.
> 
> That said, you have to use POST. If you don't use it, ES will use URL parameters (q=\* for example).
> 
> Best, if you could provide (gist) a full curl recreation, I will try to help you.
> 
> --David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 nov. 2012 à 20:26, Alexey Astafyev \<[av.astafyev@gmail.com](mailto:av.astafyev@gmail.com) ([mailto:av.astafyev@gmail.com](mailto:av.astafyev@gmail.com))\> a écrit :
> 
> > Sorry, but it doesn't help ☹
> > 
> > I get success with the following attribute and query:
> > 
> > age\_category: {  
> > id: 9,
> > 
> > name: [  
> > "age en",
> > 
> > "age ru"
> > 
> > ]
> > 
> > }
> > 
> > curl -X GET "[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)" -d '{"filter":{"terms":{"age\_category.name (http://age\_category.name)":["age en"]}}}'
> > 
> > But, when I'm trying to search on array, it fails.
> > 
> > On Tuesday, November 27, 2012 11:14:35 PM UTC+4, David Pilato wrote:
> > 
> > > Try with -XPOST
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 27 nov. 2012 à 20:07, Alexey Astafyev \<[av.as...@gmail.com](mailto:av.as...@gmail.com) (javascript:)\> a écrit :
> > > 
> > > Hello everyone,
> > > 
> > > I have a problem with filter queries.
> > > 
> > > Here is my piece of index:
> > > 
> > > broadcasting\_regions: [  
> > > {  
> > > region: {  
> > > id: 26,
> > > 
> > > name: [  
> > > "enenenen",
> > > 
> > > "rururu"
> > > 
> > > ]
> > > 
> > > },
> > > 
> > > country: {  
> > > id: 0,
> > > 
> > > name:
> > > 
> > > }
> > > 
> > > }
> > > 
> > > ],
> > > 
> > > I'm trying to filter items by 'broadcasting\_regions.region.name (http://broadcasting\_regions.region.name)' with the following curl query:
> > > 
> > > curl -X GET "[http://localhost:9200/videos/\_search?from=0&load=true&size=10&pretty=true](http://localhost:9200/videos/_search?from=0&load=true&size=10&pretty=true)" -d '{"filter":{"terms":{"broadcasting\_regions.region.name (http://broadcasting\_regions.region.name)":["rururu"]}}}'
> > > 
> > > Unfortunately I get nothing:
> > > 
> > > {  
> > > "took" : 1,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > }
> > > 
> > > Could you please tell me what's wrong with my query?
> > > 
> > > --
> > 
> > --
> 
> --

--

---

<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:** [November 27, 2012, 8:33pm UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/7 "2012-11-27T20:33:13Z")

</div>

Oh? Really?  
In fact, one of my coworker hit the same issue today using GET instead of POST  
with an Ajax call from AngularJS.  
Exactly what you just described.

Thanks for this information  
Take care  
David.

Le 27 novembre 2012 à 20:51, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) a écrit :

> > That said, you have to use POST. If you don't use it, ES will use URL  
> > parameters (q=\* for example).
> 
> No, you can use GET with /\_search and a body. But some clients (eg  
> javascript) don't support that, in which case you can use POST instead.
> 
> clint
> 
> > 
> 
> --

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 28, 2012, 10:29am UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/8 "2012-11-28T10:29:26Z")

</div>

On Tue, 2012-11-27 at 21:33 +0100, David Pilato wrote:

> Oh? Really?  
> In fact, one of my coworker hit the same issue today using GET instead  
> of POST with an Ajax call from AngularJS.  
> Exactly what you just described.

According to the REST spec, GET requests shouldn't have a body.  
According to the HTTP spec, GET requests with bodies are allowed, but  
their behaviour is undefined.

From our perspective, using GET for search seems "RESTful" (while using  
POST doesn't, as we're not changing anything) but it is quite possible  
that we want to pass a much bigger query than can be encoded in 4kB of  
query string space, so using a body seems cleaner.

However, given that Javascript (et al) does not support GET requests  
with a body, POST is also supported.

clint

--

---

<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:02am UTC](https://discuss.elastic.co/t/need-help-with-filter-on-array/9850/9 "2017-07-06T03:02:29Z")

</div>


