Hit count stats for search results


(Lifo888) #1

Hi,

I'm trying to figure out if there's a way to get the number of occurrences for the search phrase for text searches. Say i run a search for the word "apple", i want the results and also how many times "apple" appeared in the matched result. It's ok if i have to run two queries, one to get the normal search result and another query to get the occurrences count.

I know there's the _explain endpoint and it gives you some of the similar stat, but this https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-intro.html guide says it's expensive and not to use it on production cluster.

Thanks,
L


(Mark Walkom) #2

You could probably use a sum agg with a filter for apples.


(Lifo888) #3

Don't think i can use the sum agg. I want to get the number of occurrences of search phrase in each of the returned docs. Thanks for the reply tho.

Thanks,
Guang


(system) #4