Send json query to Apache Solr

The following code shows how to send an aggregation query to Solr

Assuming docs having the following minimal structure:

1
2
3
4
5
{
"response_payload": Long,
"ip": String,
"country_name": String
}

Then using curl to send a http request:

1
2
3
4
5
6
7
8
9
10
11
12
json='{
"bytes_transferred_per_country": {
"facet": {
"bytes_transferred": "sum(response_payload)",
"sources": "unique(ip)"
},
"limit": 25,
"field": "country_name",
"type": "terms"
}}'

curl -X GET http(s)://{host}/solr/{node}/select?q=*:*&json.facet={$json}&wt=json