If you want to do a simple Elasticsearch (ES) query, you can make a GET request using the URI method. In cURL, an simple example would be:
curl -X GET "https://www.example.com/vulcanIndex/_search?q=name:Spock"
Even though cURL doesn't exist in .NET, this is pretty easy to translate so it will work with HttpWebRequest.
Unfortunately, at the time of this post, the ES documentation said:
"Not all search options are exposed when executing a search using this mode..." -
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
Apparently, in order to do more "advanced" searches like Query String Queries, you have to actually pass a body with the search request which is presently shown on this Example Page:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
So apparently, if I wanted to find all Vulcan's that were not human that graduated from MIT or Starfleet academy, I might run a cURL command like this:
curl -X GET "https://www.example.com/vulcanIndex/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"query_string": {
"query": "(institution:"Starfleet Academy" OR institution: MIT) AND (NOT alternateSpecies:Human)"
}
}
}
'
Unfortunately, I don't have easy access to cURL from within ASP.NET. Most posts I've seen on the internet about emulating cURL behavior suggest I try to use the HttpWebRequest for that purpose; unfortunately, unlike cURL, HttpWebRequest does not seem to allow GET requests to pass body data:
C# HTTP Body with GET method
This poses a problem for me.
How do I perform "advanced" ES searches like a Query String Query from ASP.NET (without NEST) if the HttpWebRequest object will not allow me to send body data via GET requests?