在反序列化结果期间出现Elasticsearch.Net.UnexpectedElasticsearchClientException

use*_*835 11 c# elasticsearch nest

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

ConnectionSettings connectionSettings;
ElasticClient elasticClient;
connectionSettings = new ConnectionSettings(new 
Uri("http://192.168.2.197:9292/"));        
elasticClient = new ElasticClient(connectionSettings);
Run Code Online (Sandbox Code Playgroud)

这是我的要求:

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

这是我的模型:

public class NewsDataModel  {      
public string _id { get; set; }     
public string title { get; set; }     
public string content { get; set; }       
public string summary { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

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

Elasticsearch.Net.UnexpectedElasticsearchClientException:'无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型'System.Int64',因为该类型需要JSON基本值(例如,字符串,数字,布尔值,null)正确反序列化。要解决此错误,可以将JSON更改为JSON基本值(例如,字符串,数字,布尔值,null),或者更改反序列化类型,使其成为普通的.NET类型(例如,不像整数那样的原始类型,而不是集合类型) (例如数组或列表),可以从JSON对象反序列化。还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。路径“ hits.total.value”,第1行,位置113。”

如何解决此异常?

Krz*_*tof 16

I had the same issue, and it seems that NEST 6.6.0 library is not compatible with Elasticsearch 7.0. I had to update NEST to 7.0.0 (alpha at this point).