[英]Trying to search any word present in all of my elasticsearch documents (no field specified) in c# using NEST
I am trying to search an input word in any index or document in elasticsearch using NEST in c# 我正在尝试使用c#中的NEST在elasticsearch中的任何索引或文档中搜索输入词
I've already tried simple_string_query
, match_all
, _search
(most basic request), none of this worked and I get every time the same error message. 我已经试过
simple_string_query
, match_all
, _search
(最基本的要求),这一切都不工作,每次都遇到同样的错误消息。
var conn = new ConnectionSettings(new Uri("<elasticsearchEndpoint>))
.DefaultIndex(model.Index)
.DefaultTypeName(model.Type);
var client = new ElasticClient(conn);
var res = client.Search<dynamic*>(c=>c
.AllIndices()
.AllTypes()
.Query(q=>q
.QueryString(qs=>qs.Query(model.Query)
)
));
I've also tried with myObject class 我也试过myObject类
I expect to get a list of documents that contains the input word, or at least a list of document ids. 我希望得到一个包含输入词的文档列表,或者至少包含文档ID列表。
You will find the error below : 您将在下面找到错误:
Elasticsearch.Net.UnexpectedElasticsearchClientException : 'Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Int64' because the type requires a JSON primitive value (eg string, number, boolean, null) to deserialize correctly.
Elasticsearch.Net.UnexpectedElasticsearchClientException:'无法将当前JSON对象(例如{“name”:“value”})反序列化为类型'System.Int64',因为该类型需要JSON原语值(例如string,number,boolean,null)正确地反序列化。 To fix this error either change the JSON to a JSON primitive value (eg string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (eg not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object.
要修复此错误,请将JSON更改为JSON原始值(例如string,number,boolean,null)或更改反序列化类型,使其成为普通的.NET类型(例如,不是像整数这样的基本类型,而不是集合类型像数组或List一样,可以从JSON对象反序列化。 JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
JsonObjectAttribute也可以添加到类型中以强制它从JSON对象反序列化。 Path 'hits.total.value', line 1, position 116.'
路径'hits.total.value',第1行,第116位。'
public class ApiModel
{
[Required]
[Display(Name = "Index")]
public string Index { get; set; }
[Required]
[Display(Name = "Type")]
public string Type { get; set; }
[Required]
[Display(Name = "Id")]
public string Id { get; set; }
public dynamic Body { get; set; }
public string sent_body { get; set; }
public bool Request { get; set; }
public string Method { get; set; }
public string Rody { get; set; }
public string Query { get; set; }
}
It sounds to me like you are using a NEST 6.x client against Elasticsearch 7.x. 听起来像你正在使用NEST 6.x客户端对抗Elasticsearch 7.x. This won't work because they are not compatible;
这不起作用,因为它们不兼容; in this case, I suspect it is the change to the
"total"
field on a search response that cannot be deserialized because in 7.x it is an object
and in 6.x, it is a long
. 在这种情况下,我怀疑是搜索响应中
"total"
字段的变化无法反序列化,因为在7.x中它是一个object
而在6.x中,它是一个long
。
Please use a NEST 7.x client with Elasticsearch 7.x, which is compatible. 请使用兼容Elasticsearch 7.x的NEST 7.x客户端。 The latest at this time is 7.0.0-beta1 .
目前最新的是7.0.0-beta1 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.