Generate the counts of the search terms in one request


#1

I 'm doing text search using some key words or phrases(such as flu, fever and sore throat). Then I want to know the number of hits of each key word (phrase). I know I could do individual query request of each search term then aggregate like the following.

GET /tweets/_search?search_type=count
{
"query": {
"filtered": {"query": {"match": {"text": "flu"}}}
},
"aggs":{
"flu": {"value_count": {"field": "id"}}}
}

GET /tweets/_search?search_type=count
{
"query": {
"filtered": {"query": {"match_phrase": {"text": "sore throat"}}}
},
"aggs":{
"sore throat": {"value_count": {"field": "id"}}}
}

Is there a way that I could generate the counts of the search terms in one request and get the results like the following, because I have near one hundred search terms.

"aggregations": {
"sore throat": {"value": 429041},
"flu": {"value": 4000294},
"fever": {"value": 213302},
......
}

Thank you !


(Adrien Grand) #2

Doing multiple requests is the right approach. If you want to get everything in a single round-trip, you could use the multi-search endpoint.


(system) #3