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

Error in Creating an Index in NEST 2.3.1 (Elastic Search)

我在我的 .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 上搜索,但我只获得旧版本的帮助!

提前致谢。

Uri node        = new Uri(ES_ADDRESS);
var settings    = new ConnectionSettings(node);
settings.DisableDirectStreaming();//Check json
var client      = new ElasticClient(settings);
//Analyzers:
CustomAnalyzer shingles = new CustomAnalyzer
{
  Tokenizer = "standard",
  Filter = new List<string>()
  {
    "standard", "lowercase", "shingle"
  }
};
//Settings for index:
var mapperTemplate = new CreateIndexDescriptor(string.Format("customers"))
  .Settings(s => s
    .Analysis(a => a
      .Analyzers(an => an
        .UserDefined("analyzer_shingles", shingles)
      )
    )
  );
var customer = mapperTemplate.Mappings(ms => ms
  .Map<customers>(m => m
    .AllField(a => a.Analyzer("analyzer_shingles"))
    .AutoMap()
  )
);

//Create index:
var response = client.CreateIndex(customer);

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

对于最新版本,此代码段有效:

var indexCreated = client.CreateIndex("person",
                 s => s.Mappings(ms => ms
                 .Map<Person>(m => m)));