C#Elasticsearch NEST无法转换lambda表达式 [英] C# Elasticsearch NEST cannot convert lambda expression

查看:147
本文介绍了C#Elasticsearch NEST无法转换lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遇到与 ElasticSearch NEST搜索所描述的完全相同的问题(而不是回答)



我使用:


  1. .NET Framework 4.5; p>


  2. ASP.NET MVC 5;


  3. Elasticsearch 1.6.0(在服务器上);


  4. Elasticsearch.NET 1.6.1


  5. NEST 1.6.1

    我有一个MVC控制器有两个动作:


    1. 索引 - 其中包含HTML UI表单


    2. 搜索 - 其中包含Elasticsearch.NET客户端和查询。

        public ActionResult Search(SearchCreteria sc)
      {
      设置设置=新设置();
      客户端客户端=新客户端(设置);
      ElasticsearchClient esClient = client.Get();

      var test = esClient.Search< Contract>(body => body.Query(query => query.QueryString(qs => qs.Query(test))))

      return View(test);
      }


    整个 > body => body.Query(query => query.QueryString(qs => qs.Query(test))))上面的代码中的lambda表达式带有以下工具提示, (p)


    (参数)?身体



    错误:



    无法将lambda表达式转换为object类型,因为它不是委托类型


    我讨厌这个问题,发现在99%的情况下,人们忘记包括一个程序集,通常是 System.Linq



    嗯..我绝对不会忘记添加一个,但我可能也必须包括一个NEST的特定程序集或类似的东西我确定这不是真的,除了NEST本身),所以我决定添加一切,尽管可能有点相关,我最终结束了:

     使用系统; 
    使用System.Collections.Generic;
    使用System.Linq;
    使用System.Text;
    使用System.Threading.Tasks;

    使用System.Web.Mvc;
    使用WebUI.Models.Concrete;

    使用Domain.Concrete.Entities;
    使用Domain.Concrete.Connectivity.Elastic;
    使用Domain.Concrete.Processors.Elastic;

    使用Elasticsearch;
    使用Elasticsearch.Net;
    使用Elasticsearch.Net.Connection.Configuration;
    使用Elasticsearch.Net.Connection.RequestState;
    使用Elasticsearch.Net.Connection.Security;
    使用Elasticsearch.Net.ConnectionPool;
    使用Elasticsearch.Net.Exceptions;
    使用Elasticsearch.Net.Providers;
    使用Elasticsearch.Net.Serialization;

    使用Nest;
    使用Nest.Domain;
    使用Nest.DSL.Descriptors;
    使用Nest.DSL.Query;
    使用Nest.DSL.Query.Behaviour;
    使用Nest.DSL.Visitor;
    使用Nest.Resolvers.Converters.Aggregations;
    使用Nest.Resolvers.Converters.Filters;
    使用Nest.Resolvers.Converters.Queries;
    使用Nest.Resolvers.Writers;

    没有预期的帮助,但值得一试。所以现在,我不知道问题在哪里,任何帮助都将被高度赞赏。

    解决方案

    对这个问题本身的意见,但为未来的Google员工添加。



    Elasticsearch.NET



    是一个准系统低级 ElasticsearchClient 客户端,它只接受字符串,匿名/动态对象或 byte [] 。类似地,它也没有返回类型的响应。当这样配置时,此客户端支持连接池和节点故障转移。这个客户端的80%是自动生成的。



    只有当您与Elasticsearch进行集成时,这个客户端才有用,只有少数几个通话,你不想要引入依赖关系,例如 Json.NET 。仅使用此功能的库的示例是 Serilog.Sinks.Elasticsearch



    NEST



    高级 ElasticClient 客户端,具有所有请求和响应的99.9%的类型。 99/100次这是您要使用的客户端。 NEST使用Elasticsearch.NET来调度请求以纠正弹性搜索API端点并使用相同的连接池和故障转移基础设施。


    I'm running into exactly the same problem described (and not answered) here ElasticSearch NEST Search

    I use:

    1. .NET Framework 4.5;

    2. ASP.NET MVC 5;

    3. Elasticsearch 1.6.0 (on a server);

    4. Elasticsearch.NET 1.6.1

    5. NEST 1.6.1

    I have an MVC controller which has two actions:

    1. Index - which contains HTML UI form

    2. Search - which contains Elasticsearch.NET client and a query.

      public ActionResult Search(SearchCreteria sc)
      {
        Settings settings = new Settings();
        Client client = new Client(settings);
        ElasticsearchClient esClient = client.Get();
      
        var test = esClient.Search<Contract>(body => body.Query(query => query.QueryString(qs => qs.Query("test"))));
      
        return View(test);
      }
      

    Entire "body => body.Query(query => query.QueryString(qs => qs.Query("test")))" lambda expression in the code above has squiggly red underline with the following tooltip:

    (Parameter) ? body

    Error:

    Cannot convert lambda expression to type 'object' because it is not a delegate type

    I googled the problem and found out that in 99% of cases folks forgot to include an assembly, typically System.Linq.

    Well.. I definitely didn't forget to add that one, but I though maybe I have to include a NEST specific assembly or something like that (which I'm sure is not true, except for NEST itself), so I decided to add everything I though could be somewhat relevant and I ended up with this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using System.Web.Mvc;
    using WebUI.Models.Concrete;
    
    using Domain.Concrete.Entities;
    using Domain.Concrete.Connectivity.Elastic;
    using Domain.Concrete.Processors.Elastic;
    
    using Elasticsearch;
    using Elasticsearch.Net;
    using Elasticsearch.Net.Connection.Configuration;
    using Elasticsearch.Net.Connection.RequestState;
    using Elasticsearch.Net.Connection.Security;
    using Elasticsearch.Net.ConnectionPool;
    using Elasticsearch.Net.Exceptions;
    using Elasticsearch.Net.Providers;
    using Elasticsearch.Net.Serialization;
    
    using Nest;
    using Nest.Domain;
    using Nest.DSL.Descriptors;
    using Nest.DSL.Query;
    using Nest.DSL.Query.Behaviour;
    using Nest.DSL.Visitor;
    using Nest.Resolvers.Converters.Aggregations;
    using Nest.Resolvers.Converters.Filters;
    using Nest.Resolvers.Converters.Queries;
    using Nest.Resolvers.Writers;
    

    It didn't help as expected, but was worth a try. So now, I'm not sure where is the problem and any help would be highly appreciated.

    解决方案

    Answer was already provided in comments on the question itself but adding this for future googlers.

    Elasticsearch.NET

    Is a barebones lowlevel ElasticsearchClient client, it only accepts strings, anonymous/dynamic objects, or byte[]. Similarly it has no return types for the responses either. This client supports connection pooling and node failover when so configured. 80% of this client is automatically generated.

    This client is only useful if you are doing an integration with Elasticsearch that only exists of a handful of calls and you do not want to introduce a dependency on e.g Json.NET. An example of a library that only uses this is Serilog.Sinks.Elasticsearch

    NEST

    The high level ElasticClient client, has types for 99.9% of all the requests and responses. 99/100 times this is the client that you want to use. NEST uses Elasticsearch.NET under the hood to dispatch requests to to correct elasticsearch API endpoints and to use the same connection pooling and failover infrastructure.

    这篇关于C#Elasticsearch NEST无法转换lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆