Created
January 2, 2014 22:41
-
-
Save nathanmoon/8228507 to your computer and use it in GitHub Desktop.
elasticsearch nested facets and facet_filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE "http://localhost:9200/nestedfacets" | |
curl -XPOST "http://localhost:9200/nestedfacets/" | |
curl -XPOST "http://localhost:9200/nestedfacets/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" | |
} | |
} | |
}, | |
"owner_username" : { | |
"type" : "string", | |
"index" : "not_analyzed" | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "http://localhost:9200/nestedfacets/item/" -d ' | |
{ | |
"description" : "A really interesting item", | |
"owner_username" : "owner_one", | |
"ratings" : [{ | |
"rater_username" : "my_username", | |
"rating" : 10 | |
},{ | |
"rater_username" : "another_username", | |
"rating" : 9 | |
}] | |
} | |
' | |
curl -XPOST "http://localhost:9200/nestedfacets/_refresh" | |
curl -XPOST "http://localhost:9200/nestedfacets/item/_search?pretty=true" -d ' | |
{ | |
"query" : { | |
"term" : { | |
"description" : "interesting" | |
} | |
}, | |
"filter" : { | |
"term" : { | |
"owner_username" : "owner_one" | |
} | |
}, | |
"facets" : { | |
"ratings" : { | |
"nested" : "ratings", | |
"terms" : { | |
"field" : "ratings.rating", | |
"size" : 10 | |
}, | |
"facet_filter" : { | |
"term" : { | |
"ratings.rater_username" : "my_username" | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "http://localhost:9200/nestedfacets/item/_search?pretty=true" -d ' | |
{ | |
"query" : { | |
"term" : { | |
"description" : "interesting" | |
} | |
}, | |
"filter" : { | |
"term" : { | |
"owner_username" : "owner_one" | |
} | |
}, | |
"facets" : { | |
"ratings" : { | |
"nested" : "ratings", | |
"terms" : { | |
"field" : "ratings.rating", | |
"size" : 10 | |
}, | |
"facet_filter" : { | |
"and" : [{ | |
"term" : { | |
"ratings.rater_username" : "my_username" | |
} | |
},{ | |
"term" : { | |
"owner_username" : "owner_one" | |
} | |
}] | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment