使用 NEST / Elasticsearch.Net 执行原始 JSON 请求

Kap*_*apé 2 c# elasticsearch nest

一些(高级)请求用纯 JSON 编写比使用 NEST 提供的语法更容易。接口中有一个CreatePostAsyncIElasticLowLevelClient但它Index专门使用API。

我不想HttpClient直接使用 a ,因为那样我会缺少最大重试等功能。

是否有可能做任何对Elasticsearch(请求GETPOST使用NEST / Elasticsearch.Net客户端等)?

Rus*_*Cam 6

如果你想提出任何请求,你可以DoRequest/DoRequestAsync在低级客户端上使用

var lowLevelClient = new ElasticLowLevelClient();

var stringResponse = lowLevelClient.DoRequest<StringResponse>(
    HttpMethod.POST, 
    "_search", 
    PostData.Serializable(new
    {
        query = new { match_all = new { } }
    }));  
Run Code Online (Sandbox Code Playgroud)

还暴露在.LowLevel属性中的高级客户端 NEST 上

var client = new ElasticClient();

var stringResponse = client.LowLevel.DoRequest<StringResponse>(
    HttpMethod.POST, 
    "_search", 
    PostData.Serializable(new
    {
        query = new { match_all = new { } }
    }));
Run Code Online (Sandbox Code Playgroud)