Skip to content

Instantly share code, notes, and snippets.

@nathanmoon
Created January 2, 2014 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanmoon/8228507 to your computer and use it in GitHub Desktop.
Save nathanmoon/8228507 to your computer and use it in GitHub Desktop.
elasticsearch nested facets and facet_filters
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