Organizational Research By

Surprising Reserch Topic

Is there a way to get the number of hits for a filter without returning all the results of the filter?


 

 

using elastic-search, i am trying to use filters to count the number of links in two *****ociated models.

i have questions which has_many votes.

i have a mapping for votes, which indexes question id of each vote, and am doing

curl -xget localhost:9200/votes/_search -d '{query : {"constant_score" : {"filter" : { "term" : {"question_id" : 5} }, "boost" : 1.0 } }}'

the problem is that this returns all the results. is it possible to simply grab a count instead?


asked May 16, 2015 in SOLR by rajesh
0 votes
21 views



Related Hot Questions

1 Answer

0 votes

just add search_type=count to your query string:

curl -xget localhost:9200/votes/_search?search_type=count -d '{ "query" : { "constant_score" : { "filter" : { "term" : {"question_id" : 5} } } }}'

that said, as @phoet suggested, you may want to use facets instead.

for example, for top 10 questions:

curl -xget 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count' -d '{ "facets" : { "votes" : { "terms" : { "field" : "question_id" } } }}'

or for just 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" } } }}'

 

 

answered May 16, 2015 by rajesh

...