【发布时间】:2019-04-16 08:54:35
【问题描述】:
我有一个 c# 项目,我想向我的弹性搜索服务器发送请求。 这是我的连接和弹性搜索客户端:
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: '无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Int64' 因为该类型需要 JSON 原始值(例如 string, number, boolean, null) 来正确反序列化。 要修复此错误,请将 JSON 更改为 JSON 原始值(例如字符串、数字、布尔值、null)或更改反序列化类型 所以它是一个普通的 .NET 类型(例如,不是像 整数,而不是数组或列表之类的集合类型) 从 JSON 对象反序列化。也可以添加 JsonObjectAttribute 强制它从 JSON 对象反序列化的类型。 路径“hits.total.value”,第 1 行,位置 113。
我该如何解决这个异常?
【问题讨论】:
标签: c# elasticsearch nest