Can you share a reproduction of the mismatches you're experiencing? (in a gist or something like that, so that I can see on what data you're running these queries)
The has_parent query in a must clause should return all child documents with a parent and a has_parent in must_not should return all child docs with no parent. Also on what ES version are you running this? On 2 October 2014 20:27, Tom Miller <[email protected]> wrote: > I have two documents, both (should) have a parent (different parents, but > the same type). > > However, I don't get the result I expect - especially trying to return > documents *without* a parent. > > For example: > > { > "fields":["_parent"], > "query": { > "filtered": { > "query": { > "query_string": { > "query": "kittens*" > } > }, > "filter": { > "bool": { > "must_not": [ > { > "has_parent": { > "parent_type": "psa", > "query": { > "match_all": {} > } > } > } > ] > } > } > } > } > } > > I run that, and I get this back: > > { > "took": 287, > "timed_out": false, > "_shards": { > "total": 1, > "successful": 1, > "failed": 0 > }, > "hits": { > "total": 1, > "max_score": 1, > "hits": [ > { > "_index": "egroup", > "_type": "document", > "_id": "6_9104", > "_score": 1, > "fields": { > "_parent": "6_905" > } > } > ] > } > } > > > Clearly it DOES have a parent because it shows in the results! > > If I change the initial query from "must_not" to "must", I get the other > document in the result: > > { > "took": 75, > "timed_out": false, > "_shards": { > "total": 1, > "successful": 1, > "failed": 0 > }, > "hits": { > "total": 1, > "max_score": 1, > "hits": [ > { > "_index": "egroup", > "_type": "document", > "_id": "6_9106", > "_score": 1, > "fields": { > "_parent": "6_847" > } > } > ] > } > } > > One query should return zero results, and the other should return 2. > However each are returning 1. > > Am I being thick, or is something amiss here - and how can I troubleshoot > it? > > > Tom. > > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/c8beeddf-2cfb-4af7-8836-6779baf85933%40googlegroups.com > <https://groups.google.com/d/msgid/elasticsearch/c8beeddf-2cfb-4af7-8836-6779baf85933%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Met vriendelijke groet, Martijn van Groningen -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CA%2BA76TwRGkJWWRLeV_Hv4kV1U3-zWN12pVuLsspmQRH3PSM7Kw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
