c# - NEST 2.3.1 (Elastic Search) 创建索引出错

标签 c# elasticsearch indexing delegates nest

我在我的 .NET 项目中使用 NEST 2.3.1。

我对它很陌生。

正如我在一个教程中看到的那样,我已经完成了这段代码。

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Xml.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nest;
using Newtonsoft.Json;
using System.Data.Entity;

namespace Elastic_ConsoleApp
{
    class Program
    {
        public static Uri node;
        public static ConnectionSettings settings;
        public static ElasticClient client;

        static void Main(string[] args)
        {
            node = new Uri("http://localhost:9200");
            settings = new ConnectionSettings(node);
            client = new ElasticClient(settings);
            settings.DefaultIndex("my_blog");

            var indexSettings = new IndexSettings();
            indexSettings.NumberOfReplicas = 1;
            indexSettings.NumberOfShards = 1;

            client.CreateIndex(c => c
                .Index("my_blog")
                .InitializeUsing(indexSettings)
                .AddMapping<Post>(m => m.MapFromAttributes()));
        }
    }
}

但它不起作用,我收到此错误:

Error CS1660 Cannot convert lambda expression to type 'IndexName' because it is not a delegate type

在线:

client.CreateIndex(c => c
                    .Index("my_blog")
                    .InitializeUsing(indexSettings)
                    .AddMapping<Post>(m => m.MapFromAttributes()));

我已经尝试在 Google 上搜索,但我只得到旧版本的帮助!

提前致谢。

最佳答案

您正在使用新的 ElasticSearch Nest 尝试旧方法。 您的代码将适用于 NEST Ver。 1.X. 更新您的代码以获得新版本,或者您可以使用旧版本的 NEST。

关于c# - NEST 2.3.1 (Elastic Search) 创建索引出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37405665/

相关文章:

sql - PostgreSQL 不在过滤的多重排序查询上使用索引

Mysql 字符串索引

c# - 为什么渲染属性时需要转义 < 和 & ?

spring - Spring数据版本兼容性VS Elasticsearch版本兼容性

c# - 使用 Take() 从字节数组中获取字节,在 Take() 之后无法转换回 byte[]

elasticsearch - 从elasticsearch批量删除文档后,删除文档的大小没有马上释放?

elasticsearch - 查询elasticsearch可以通过id获取文档,但无法在全部查询中找到它

HTML 索引的 jQuery 问题

c# - NEST 5.x是否依赖于NEST 2.x?

c# - 在单元测试中使用 swisstopo.dll