I have elasticsearch 6.7 running on a CentOs 7 machine, and I have node-red running from where I try to query the elastic search.
Using the httprequest node (in node-red) works great when I need to POST data to server, or when I need to perform simple GET _search queries where I can simply send parameters in the url, such as :
http://xxx.xxx.xxx.xxx:9200/data/default/_search?size={{{size}}}&from={{{from}}}&q=sensor:temp
As described in this question.
But if I need more complex queries that have nested parameters I cannot perform it with parameters through the url. For example how would I make this cURL GET with the httprequest node in node-red:
curl -XGET "http://xxx.xxx.xxx.xxx:9200/data/default/_search" -H 'Content-Type: application/json' -d'
{
"size": 0,
"query": {
"range":{
"created":{
"gte":"2019-03-11",
"lte":"2019-03-12"
}
}
},
"aggs": {
"status_terms": {
"terms": {
"field": "device.keyword"
},
"aggs": {
"status_stats": {
"stats": {
"field": "value"
}
}
}
}
}
}'
Note that you can send the whole body in the query string as a parameters.
It would look like this:
curl -XGET 'http://xxx.xxx.xxx.xxx:9200/data/default/_search?source_content_type=application/json&source={"size":0,"query":{"range":{"created":{"gte":"2019-03-11","lte":"2019-03-12"}}},"aggs":{"status_terms":{"terms":{"field":"device.keyword"},"aggs":{"status_stats":{"stats":{"field":"value"}}}}}}'