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

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

问题描述

我运行到正好说明了同样的问题(而不是回答)这里 ElasticSearch NEST搜索

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

我使用的:


  1. .NET框架4.5;

  1. .NET Framework 4.5;

ASP.NET MVC 5;

ASP.NET MVC 5;

Elasticsearch 1.6.0(在服务器上);

Elasticsearch 1.6.0 (on a server);

Elasticsearch.NET 1.6.1

Elasticsearch.NET 1.6.1

NEST 1.6.1

NEST 1.6.1

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

I have an MVC controller which has two actions:


  1. 指数 - 包含HTML表单的用户界面

  1. Index - which contains HTML UI form

搜索 - 其中包含Elasticsearch.NET客户机和查询

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);
}


整个人体=> body.Query(查询=> query.QueryString(QS => qs.Query(测试)))的代码中的lambda表达式上面有波浪红色下划线具有以下提示:

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:

(参数)?身体

错误:

无法转换lambda表达式键入对象,因为它不是一个委托类型

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

我GOOGLE了这个问题,并发现了案件的乡亲在99%忘了包括装配,通常 System.Linq的

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

嗯..我绝对没忘了补充一点,但是我虽然也许我必须包括一个特定NEST装配或类似的东西(我敢肯定是不正确的,除了本身NEST),所以我决定将我的一切,虽然可能会有些相关,我结束了这一点:

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.

推荐答案

了答案已在提供对这个问题本身,而是添加此为未来的Google意见。

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

Elasticsearch.NET

时的准系统低级 ElasticsearchClient 客户端,它只接受字符串,匿名/动态物体,或字节[] 。同样它没有返回类型的答复要么。该客户端支持连接池和节点故障转移如此配置的时候。此客户端的80%是自动生成的。

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.

如果你正在做Elasticsearch整合,只有存在呼叫的一小撮此客户端是唯一有用的,你不想要引进的如 Json.NET 的依赖。库的一个例子只使用这是 Serilog.Sinks.Elasticsearch

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

高水平 ElasticClient 客户端,有类型的所有请求和响应的99.9%。 99/100倍,这是您要使用的客户端。 NEST使用Elasticsearch.NET引擎盖下派遣请求纠正elasticsearch API端点,并使用相同的连接池和故障转移的基础设施。

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天全站免登陆