Need help with filter on array

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"
-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?

--

Try with -XPOST

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

Le 27 nov. 2012 à 20:07, Alexey Astafyev 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" -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?

--

Sorry, but it doesn't help :frowning:

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"
-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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 nov. 2012 à 20:07, Alexey Astafyev <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"
-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?

--

--

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

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

Sorry, but it doesn't help :frowning:

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" -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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 nov. 2012 à 20:07, Alexey Astafyev 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" -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?

--

--

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

--

Thank you David,

FilteredQuery helped me.

--
Alexey Astafyev
Sent with Sparrow (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 :wink:
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 :frowning:

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" -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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 nov. 2012 à 20:07, Alexey Astafyev <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" -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?

--

--

--

--

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 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://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

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

--