Просто добавьте search_type=count
в строку запроса:
curl -XGET localhost:9200/votes/_search?search_type=count -d '{
"query" : {
"constant_score" : {
"filter" : { "term" : {"question_id" : 5} }
}
}
}'
При этом, как подсказал @phoet, вы можете вместо этого использовать фасеты.
Например, для 10 лучшихвопросы:
curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count' -d '
{
"facets" : {
"votes" : {
"terms" : {
"field" : "question_id"
}
}
}
}
'
Или просто вопрос_ид 5:
curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count' -d '
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"question_id" : 5
}
}
}
},
"facets" : {
"votes" : {
"terms" : {
"field" : "question_id"
}
}
}
}
'