Help- Query DSL _search POST

Please help me with this problem.

I have a .net core client like this:

var client = new RestClient();
client.BaseUrl = new Uri(Host);
client.AddDefaultHeader("Content-Type", "application/json");

    var request = new RestRequest();
    request.Resource = "_search";           
    request.AddJsonBody(queryDslKibana);
    request.Method = Method.POST;
    request.AddHeader("Content-Type", "application/json");
    request.RequestFormat = DataFormat.Json;

Uri: http://URL:PORT/_search

the queryDslKibana is the following, I tried with a simple one but is the same problem

{"query":{"match":{"message":".Txt"}}}

It runs on postman gracefully but the response on .net is:

{
"error": {
"root_cause": [{
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] but found [VALUE_STRING]",
"line": 1,
"col": 1
}],
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] but found [VALUE_STRING]",
"line": 1,
"col": 1
},
"status": 400
}
Please help :slight_smile:

Are you sending a request to Elasticsearch or Kibana? It looks like you're talking to Elasticsearch directly. Are you using the official .net client? If so you might get more help in the Elasticsearch forum.

to kibana api to the _search endpoint.

Thanks by your support and answer, I already found the problem!

The problem was the .net RestClient because I have to send an object ( anonimous object or strong typed object) so...

The answer on code is:

var client = new RestClient();
client.BaseUrl = new Uri(Host);
client.AddDefaultHeader("Content-Type", "application/json");

        var request = new RestRequest();
        request.Resource = "_search";
        //{"query":{"match":{"message":"SEPP"}}}
        request.AddJsonBody(new { query = new { match = new { message = "SEPP" } } });
        request.Method = Method.POST;
        request.AddHeader("Content-Type", "application/json");
        request.RequestFormat = DataFormat.Json;

        IRestResponse response = client.ExecutePostTaskAsync(request).Result;

I dont know if I should delete this topic because is more a thing with .net but maybe it will be usefull to someone I guess

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.