The query as written will return a result because you are querying for
*Parent* documents that 'have children' matching your has_child query. You
can tell because the type in the url will be 'Foo'.

Hence, the filter you have specified is not run against the children, but
against the *parents*. In your example the parent document does indeed have
a access:yes field and does not get filtered out.

It is probably possible to do what you want, but it depends on whether you
are trying to retrieve parent or child documents.

To get parent documents, just add your filter criteria to the has_child
query.

To get child documents, use 'Bar' in the url and take a look into the
has_parent filter/query



On Wed, Mar 11, 2015 at 10:23 AM, asanderson <a.steven.ander...@gmail.com>
wrote:

> Is a filtered has_child query possible where the filter is applied to the
> child document before the query of the has_child?
>
> e.g. Given the example below...
>
> curl -X PUT "http://localhost:9200/foobar"; -d
> "{\"mappings\":{\"Foo\":{},\"Bar\":{\"_parent\":{\"type\":\"Foo\"}}}}"
>
> curl -X PUT "http://localhost:9200/foobar/Foo/1";
> -d "{\"foo\":\"abc\",\"access\":\"yes\"}"
>
> curl -X PUT "http://localhost:9200/foobar/Bar/2?parent=1";
> -d "{\"bar\":\"xyz\",\"access\":\"no\"}"
>
> The following filtered query should not return a result, if the filter was
> being applied to the child document first.
>
> {
>    "query": {
>       "filtered": {
>          "query": {
>             "has_child": {
>                "type": "Bar",
>                "query": {
>                   "term": {
>                      "bar": "xyz"
>                   }
>                }
>             }
>          },
>          "filter": {
>             "term": {
>                "access": "yes"
>             }
>          }
>       }
>    }
> }
>
> Please advise.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/575c3aa3-169d-4f00-b353-9e54291da432%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/575c3aa3-169d-4f00-b353-9e54291da432%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAFps6aCsz%2B%2B%3DduMCZcR--T9s2eczn0Yq1jCftma9ae0KdaR%3Ddw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to