I've just upgraded to Elastic Search 1.5.0 and so far I can't make inner_hits work with a nested filter, although it works fine with a nested query.
Let's say I want to retrieve the inner nested object actors within a movie object.
When I run the following nested query :
Syntax 1
GET my_index/movie/_search
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"nested": {
"path": "actors",
"query": {
"match": {
"actors.id": 12345
}
},
"inner_hits" : {}
}
}
}
}
}
=> I get the inner_hits as documented here, which is just fine.
But when I try doing the equivalent query with a nested filter :
Syntax 2
GET my_index/movie/_search
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"nested": {
"path": "actors",
"filter": {
"term": {
"actors.id": 12345
}
},
"inner_hits" : {}
}
}
}
}
}
=> I get the following parse error
QueryParsingException[[my_index] [nested] requires either 'query' or 'filter' field]
(and this last query works fine when I remove inner_hits - except of course that I don't get the inner hits ...)
Is there something wrong in the syntax I use or is the inner_hits not implemented yet with nested filter ?
Thanks in advance
Edit 3-30-2015
It works with the syntax provided below by @mdewit (thanks!)
Syntax 3
GET my_index/movie/_search
{
"query": {
"nested": {
"path": "actors",
"query": {
"filtered": {
"filter": {
"term": {"actors.id": 12345}
}
}
},
"inner_hits" : {}
}
}
}
even though this syntax does not match the Nested Filter doc
=> I still do not understand what is wrong with Syntax 2. It seems like an ES bug to me.
Edit 04-22-2015 : bug fixed in ES 1.5.1, see my comment below
The following seems to work:
GET my_index/movie/_search
{
"query": {
"nested": {
"path": "actors",
"query": {
"filtered": {
"filter": {
"term": {"actors.id": 12345}
}
}
},
"inner_hits" : {}
}
}
}'
Bug fixed in ElasticSearch 1.5.1 as stated here
So this syntax works (and works fine)
GET my_index/movie/_search
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"nested": {
"path": "actors",
"filter": {
"term": {
"actors.id": 12345
}
},
"inner_hits" : {}
}
}
}
}
}
Thanks guys!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With