I am having trouble with a filter.  I have items in my index, with nested 
"ratings"

curl -XPOST "http://localhost:9200/nestedfilters/item/_mapping"; -d '
{
    "item" : {
        "properties" : {
            "description" : {
                "type" : "string"
            },
            "ratings" : {
                "type" : "nested",
                "properties" : {
                    "rater_username" : {
                        "type" : "string",
                        "index" : "not_analyzed"
                    },
                    "rating" : {
                        "type" : "integer",
                        "index" : "not_analyzed"
                    }
                }
            }
        }
    }
}
'

I want to be able to find items where a certain user has not rated the 
item. I have tried using NOT, but it finds anything rated by anybody else, 
regardless of whether the specific user has rated it.  I can't seem to 
figure out how to use a MISSING filter either. Here is what I have tried:

curl -XPOST "http://localhost:9200/nestedfilters/item/_search?pretty=true"; 
-d '
{
    "query" : {
        "match_all" : {}
    },
    "filter" : {
        "nested" : {
            "path" : "ratings",
            "filter" : {
                "not" : {
                    "term" : {
                        "ratings.rater_username" : "user1"
                    }
                }
            }
        }
    }
}
'

and


curl -XPOST "http://localhost:9200/nestedfilters/item/_search?pretty=true"; 
-d '
{
    "query" : {
        "match_all" : {}
    },
    "filter" : {
        "nested" : {
            "path" : "ratings",
            "filter" : {
                "and" : [{
                    "term" : {
                        "ratings.rater_username" : "user1"
                    }
                },{
                    "missing" : {
                        "field" : "ratings.rating"
                    }
                }]
            }
        }
    }
}
'

Here is the gist with a full example: 
 https://gist.github.com/nathanmoon/8339950.

Is there another way I haven't thought of to craft a filter like this?  Or 
do I need to index my data differently to support this type of filtering? 
 Thanks for any help!

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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/fc6ce18d-2923-4b87-b992-fc81a72c69a4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to