使用 NEST / Elasticsearch.Net 执行原始 JSON 请求
Execute raw JSON request using NEST / Elasticsearch.Net
一些(高级)请求比使用 NEST 提供的语法更容易用纯 JSON 编写。
IElasticLowLevelClient
界面中有一个 CreatePostAsync
,但它专门使用 Index
API。
我不想直接使用 HttpClient
,因为这样我会缺少 maximum retries 等功能
是否可以使用 NEST / Elasticsearch.Net 客户端向 Elasticsearch(GET
、POST
等)发出 任何 请求?
如果您使用的是 NEST,则可以使用 Raw
查询。 https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/raw-query-usage.html
Allows a query represented as a string of JSON to be passed to NEST’s
Fluent API or Object Initializer syntax. This can be useful when
porting over a query expressed in the query DSL over to NEST.
您应该可以执行以下操作:
query.Raw(yourJsonQueryString)
编辑:
如果你想做一个 _reindex
你可以使用重建索引 API.
var reindexResponse = client.ReindexOnServer(r => r
.Source(s => s
.Index("old-index")
)
.Destination(d => d
.Index("new-index")
)
.WaitForCompletion(true)
);
如果你想任何请求,你可以在低级客户端上使用DoRequest/DoRequestAsync
var lowLevelClient = new ElasticLowLevelClient();
var stringResponse = lowLevelClient.DoRequest<StringResponse>(
HttpMethod.POST,
"_search",
PostData.Serializable(new
{
query = new { match_all = new { } }
}));
也在 .LowLevel
属性
中的高级客户端 NEST 上公开
var client = new ElasticClient();
var stringResponse = client.LowLevel.DoRequest<StringResponse>(
HttpMethod.POST,
"_search",
PostData.Serializable(new
{
query = new { match_all = new { } }
}));
一些(高级)请求比使用 NEST 提供的语法更容易用纯 JSON 编写。
IElasticLowLevelClient
界面中有一个 CreatePostAsync
,但它专门使用 Index
API。
我不想直接使用 HttpClient
,因为这样我会缺少 maximum retries 等功能
是否可以使用 NEST / Elasticsearch.Net 客户端向 Elasticsearch(GET
、POST
等)发出 任何 请求?
如果您使用的是 NEST,则可以使用 Raw
查询。 https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/raw-query-usage.html
Allows a query represented as a string of JSON to be passed to NEST’s Fluent API or Object Initializer syntax. This can be useful when porting over a query expressed in the query DSL over to NEST.
您应该可以执行以下操作:
query.Raw(yourJsonQueryString)
编辑:
如果你想做一个 _reindex
你可以使用重建索引 API.
var reindexResponse = client.ReindexOnServer(r => r
.Source(s => s
.Index("old-index")
)
.Destination(d => d
.Index("new-index")
)
.WaitForCompletion(true)
);
如果你想任何请求,你可以在低级客户端上使用DoRequest/DoRequestAsync
var lowLevelClient = new ElasticLowLevelClient();
var stringResponse = lowLevelClient.DoRequest<StringResponse>(
HttpMethod.POST,
"_search",
PostData.Serializable(new
{
query = new { match_all = new { } }
}));
也在 .LowLevel
属性
var client = new ElasticClient();
var stringResponse = client.LowLevel.DoRequest<StringResponse>(
HttpMethod.POST,
"_search",
PostData.Serializable(new
{
query = new { match_all = new { } }
}));