简体   繁体   English

尝试使用NEST搜索c#中所有弹性搜索文档中的任何单词(没有指定字段)

[英]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_querymatch_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.

相关问题 为什么使用 C#/ElasticSearch 进行此 NEST 通配符搜索时没有返回任何文档? - Why are no documents returned with this NEST wildcard search with C#/ElasticSearch? 需要从ElasticSearch返回Distinct字段,而无需使用C#和Nest的完整搜索结果文档 - Need to return Distinct fields from ElasticSearch without the full search result documents using C# and Nest 使用ElasticSearch(C#/ NEST)获取按时间戳排序的所有文档 - With ElasticSearch (C#/NEST) get all documents sorted by timestamp C#NEST ElasticSearch搜索并突出显示所有类型的所有字段 - C# NEST ElasticSearch search and highlight all fields in all types 使用 Nest + C# 在弹性搜索中查找具有空字段/Attachment.Content 的文档 - find documents with empty field / Attachment.Content in elastic search using Nest + C# 如何使用 C# NEST 在 ElasticSearch 中搜索数组的动态元素? - How to search dynamic elements of array in ElasticSearch using C# NEST? C#为Elasticsearch嵌套:如何将更新弹性搜索文档特定字段的查询转换为Nest? - c# nest for elasticsearch: how to convert query that updates particular field of elastic search document to nest? 使用Highlight C#Nest进行ElasticSearch查询搜索 - ElasticSearch Query Search with Highlight C# Nest NEST搜索整个文档C#Elasticsearch - NEST Search whole document C# Elasticsearch NEST-术语为空时,MultiMatch搜索所有文档-Elasticsearch 6.4 - NEST - MultiMatch search all documents when term is empty - Elasticsearch 6.4
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM