gpt4 book ai didi

c# - Elasticsearch.Net.UnexpectedElasticsearchClientException 在反序列化结果

转载 作者:可可西里 更新时间:2023-11-01 08:41:51 24 4
gpt4 key购买 nike

我有一个 c# 项目,我想向我的 Elasticsearch 服务器发送一个请求。这是我的连接和 Elasticsearch 客户端:

ConnectionSettings connectionSettings;
ElasticClient elasticClient;
connectionSettings = new ConnectionSettings(new
Uri("http://192.168.2.197:9292/"));
elasticClient = new ElasticClient(connectionSettings);

这是我的要求:

var response = elasticClient.Search<NewsDataModel>(s => s
.Index("news-index")
.Type("title")
.Query(q => q.QueryString(qs => qs.Query("ny"))));

这是我的模型:

public class NewsDataModel  {      
public string _id { get; set; }
public string title { get; set; }
public string content { get; set; }
public string summary { get; set; }
}

但是当我发送请求时,我得到了这个异常:

Elasticsearch.Net.UnexpectedElasticsearchClientException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int64' because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly. To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'hits.total.value', line 1, position 113.'

如何解决这个异常?

最佳答案

我遇到了同样的问题,似乎 NEST 6.6.0 库与 Elasticsearch 7.0 不兼容。我必须将 NEST 更新到 7.0.0(此时为 alpha)。

关于c# - Elasticsearch.Net.UnexpectedElasticsearchClientException 在反序列化结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55704224/

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