Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用NEST/Elasticsearch.Net执行原始JSON请求_C#_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest - Fatal编程技术网 elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

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

C# 使用NEST/Elasticsearch.Net执行原始JSON请求,c#,elasticsearch,nest,C#,elasticsearch,Nest,一些(高级)请求使用纯JSON编写比使用NEST提供的语法更容易。 在IElasticLowLevelClient界面中有一个CreatePostAsync,但它专门使用索引API 我不想直接使用HttpClient,因为这样我就缺少了诸如etc之类的功能 是否可以使用NEST/Elasticsearch.Net客户端对Elasticsearch进行任何请求(GET,POST等)?如果您使用的是NEST,则可以使用Raw查询 允许将表示为JSON字符串的查询传递给NEST的 流畅的API或对象初

一些(高级)请求使用纯JSON编写比使用NEST提供的语法更容易。 在
IElasticLowLevelClient
界面中有一个
CreatePostAsync
,但它专门使用
索引
API

我不想直接使用
HttpClient
,因为这样我就缺少了诸如etc之类的功能


是否可以使用NEST/Elasticsearch.Net客户端对Elasticsearch进行任何请求(
GET
POST
等)?

如果您使用的是NEST,则可以使用
Raw
查询

允许将表示为JSON字符串的查询传递给NEST的 流畅的API或对象初始值设定项语法。这在以下情况下非常有用: 在查询DSL中表示的查询上移植到嵌套

您应该能够执行以下操作:

query.Raw(yourJsonQueryString)
编辑: 如果要执行reindex,可以使用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 { } }
    }));  

就我所知,这只是用于查询(搜索),我希望只使用JSONA执行任何请求,比如执行
POST\u reindex
,你是说发送文本json吗?所有操作的低级客户端调用都采用json格式的字符串,请参见此处的示例@sramalingam24 Yes,例如我的
\u reindex
示例,类似于
ReindexAsync(PostData.string(“我的json”)
在低层客户端上确实可以工作,谢谢!很酷,没有问题这将很好地用于低层客户端上的非内置命令,谢谢!@Kapé低层客户端的目标是实现所有非实验性API。有时客户端可以跟踪Elasticsearch,因此尚未实现API,但是否有特定的API你在找什么?现在我只需要
\u reindex
API,但我没有注意到低层客户端上允许你输入JSON的方法
var client = new ElasticClient();

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