gpt4 book ai didi

c# - 来自Elasticsearch请求的无效NEST响应-无效的文档格式

转载 作者:行者123 更新时间:2023-12-03 02:27:39 26 4
gpt4 key购买 nike

我开始使用Elasticsearch NEST API((I saw this post related),并且试图找出查询/对象可能出了什么问题。

这是我的文档对象:

public class Jenson_Elastic_Log
{
public string exception { get; set; }
public string http_context { get; set; }

[JsonConverter(typeof(MyDateTimeConverter))]
public DateTime log_date { get; set; }
public string log_level { get; set; }
public string logger { get; set; }
public string message { get; set; }
public string server_name { get; set; }
}

我用来查询索引的代码:
 var settings = new ConnectionSettings(new Uri("http://localhost:9200/")).DefaultIndex("jenson_logging");

var client = new ElasticClient(settings);

var testLog = new Jenson_Elastic_Log
{
exception = "test",
http_context = "local",
log_date = DateTime.Now,
log_level = "High",
logger = "testing",
message = "test push log",
server_name = "localhost"
};


var indexResponse = client.IndexDocument(testLog);
var asyncIndexResponse = client.IndexDocument(indexResponse);

这总是抛出错误:“{无效的NEST响应是由POST上的不成功(400)低级调用构建的:/ jenson_logging / _doc}”(该错误伴随有/不存在datetimeconverter出现)

这是我要查询的索引的json对象的样子:

https://jsoneditoronline.org/#left=cloud.ff3388575dc945688a446884bfcf1814

对此查询的任何帮助将不胜感激。

最佳答案

我的怀疑是索引"jenson_logging"包含一个不是"_doc"的现有文档映射,当尝试用7.x客户端索引文档时会导致400 Bad Request。通过查看 indexResponse.DebugInformation ,您应该能够获得有关错误原因的更多详细信息。

7.x客户端没有公开发送除"_doc"之外的任何其他文档类型的方法,因为types are deprecated in Elasticsearch and will be removed in future。索引到Elasticsearch的其他系统可能仍在"_doc"之外的7.x中设置其他doc类型,但我会强烈建议将其更改为使用"_doc",因为它将在集群升级到新的主要版本时进行准备。 future 。

另外,为了支持POCO上的JsonNetSerializer,还需要连接 [JsonConverter(typeof(MyDateTimeConverter))]

关于c# - 来自Elasticsearch请求的无效NEST响应-无效的文档格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60729736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com