8

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

2 Answers 2

6

The following seems to work:

GET my_index/movie/_search
{
    "query": {
        "nested": {
            "path": "actors",
            "query": {
                "filtered": {
                    "filter": {
                        "term": {"actors.id": 12345}
                    }
                }
            },
            "inner_hits" : {}
        }
    }
}'
Sign up to request clarification or add additional context in comments.

1 Comment

Yep it works, thanks for that! Nevertheless, I'll leave the question open as the syntax you provided isn't exactly the one described in the official Nested Filter documentation : elastic.co/guide/en/elasticsearch/reference/1.x/… I still reckon there's something wrong in the error message I get from ES in the example I provided
3

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.