Kibana Post 搜索 - 预期 [START_OBJECT] 但找到 [VALUE_STRING]

Kibana Post Search - Expected [START_OBJECT] but found [VALUE_STRING]

请帮我解决这个问题。

我有一个这样的 .net 核心客户端:

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;

网址: http://URL:PORT/_search

queryDslKibana 如下:

{"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
 }

请帮忙:)

在我看来,变量 "queryDslKibana" 没有合适的 JSON 格式,当使用方法“AddJsonBody()”时,它是对象具有适当的格式很重要。 “AddJsonBody()”方法序列化你发送的对象,所以你应该先尝试匿名对象。

类似的东西:

var requestObject = new {query = new {match = new {message = ".txt"}}};

这应该会产生您需要的 JSON:

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

谢谢@michael。

最终代码为:

到 kibana api 到 _search 端点。

问题出在 .net RestClient,因为我必须像您所说的那样发送一个对象(匿名对象或强类型对象)...

代码的答案是:

        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;