Skip to content

Instantly share code, notes, and snippets.

@darklow
Last active December 21, 2015 11:08
Show Gist options
  • Save darklow/6296391 to your computer and use it in GitHub Desktop.
Save darklow/6296391 to your computer and use it in GitHub Desktop.
// mapping
{
"credits": {
"properties": {
"position": {
"type": "integer"
},
"person": {
"properties": {
"id": {
"type": "integer"
}
}
}
}
}
// query
{
"size": 0,
"facets": {
"top_roles": {
"terms": {
"field": "credits.person.id"
}
}
}
}
// Solution using "nested"
{
"query": {
"term": {
"tv": "7"
}
},
"size": 0,
"facets": {
"top_cast": {
"terms_stats": {
"key_field": "credits.person.id",
"value_field": "credits.person.position",
"order": "min"
},
"nested": "credits",
"facet_filter": {
"term": {
"credits.department": "actor"
}
}
}
}
}
// If count is identical for several credits items,
// is it possible to somehow adjust count and
// involve second parameter - position, that changes count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment