c# - Kibana 帖子搜索 - 应为 [START_OBJECT],但找到了 [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;
URI : http://URL:PORT/_search
查询DslKibana 如下:
{"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"}}}
推荐阅读
- python - Python:未定义函数名称
- sql-server - 如何将 SaaS 应用程序与我们的本地 SQL Server 集成?
- apache-kafka - Kafka Streams:Kerberos 票据续订
- x86 - 如何更改 VirtualBox 为来宾操作系统模拟的 CPU 指令集,例如禁用 SSE4.2 指令集?
- c# - unity脚本无法导出
- html - 如何给字体填充?
- java - 如何将字符串转换为整数类型并从用户输入中输入双精度?
- python - 比较 Python 中两个文件的非重复文件内容格式
- python - 为什么 CoreNLP ner tagger 和 ner tagger 将分开的数字连接在一起?
- python - 在线统计 Python:方差计算不正确