Behavior of missing and exists with nested objects

I am trying to figure out how missing/exists works with nested objects, and
what I am seeing is very strange. Here is a gist to demonstrate:
https://gist.github.com/nathanmoon/8344115

I have a nested object, ratings, with a mapping like:

        "ratings" : {
            "type" : "nested",
            "properties" : {
                "rater_username" : {
                    "type" : "string",
                    "index" : "not_analyzed"
                },
                "rating" : {
                    "type" : "integer",
                    "index" : "not_analyzed"
                }
            }
        }

My data looks like this:

curl -XPOST "http://localhost:9200/nestedfilters/item/" -d '
{
"description" : "Rated by user1",
"ratings" : [{
"rater_username" : "user1",
"rating" : 10
}]
}
'

curl -XPOST "http://localhost:9200/nestedfilters/item/" -d '
{
"description" : "Rated but missing username",
"ratings" : [{
"rating" : 10
}]
}
'

curl -XPOST "http://localhost:9200/nestedfilters/item/" -d '
{
"description" : "Rated by empty set",
"ratings" : []
}
'

curl -XPOST "http://localhost:9200/nestedfilters/item/" -d '
{
"description" : "Rated by nobody",
}
'

Here is what I'm getting with various filters (sorry for the formatting):


FILTER:

"filter" : {
    "missing" : {
        "field" : "ratings"
    }
}

WHAT I WOULD EXPECT:

"Rated by empty set"
"Rated by nobody"

IT RETURNS:

"Rated by user1"
"Rated but missing username"
"Rated by empty set"


FILTER:

"filter" : {
    "nested" : {
        "path" : "ratings",
        "filter" : {
            "missing" : {
                "field" : "ratings.rating"
            }
        }
    }
}

WHAT I WOULD EXPECT:

"Rated by empty set"
"Rated by nobody"

IT RETURNS:

[empty set]


FILTER:

"filter" : {
    "not" : {
        "nested" : {
            "path" : "ratings",
            "filter" : {
                "exists" : {
                    "field" : "ratings.rating"
                }
            }
        }
    }
}

WHAT I WOULD EXPECT:

"Rated by empty set"
"Rated by nobody"

IT RETURNS:

"Rated by empty set"


FILTER:

"filter" : {
    "not" : {
        "nested" : {
            "path" : "ratings",
            "filter" : {
                "exists" : {
                    "field" : "ratings.rater_username"
                }
            }
        }
    }
}

WHAT I WOULD EXPECT:

"Rated but missing username"
"Rated by empty set"
"Rated by nobody"

IT RETURNS:

"Rated but missing username"
"Rated by empty set"


Can anyone explain what I am seeing, and what is the best way to index and
query for 'missing' nested fields? Thank you!

Nathan

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/eee98195-312f-4722-81ae-4c8c39e1f029%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.