elasticsearch,indexing,delegates,nest,C#,elasticsearch,Indexing,Delegates,Nest" /> elasticsearch,indexing,delegates,nest,C#,elasticsearch,Indexing,Delegates,Nest" />

C# 在NEST 2.3.1(弹性搜索)中创建索引时出错

C# 在NEST 2.3.1(弹性搜索)中创建索引时出错,c#,elasticsearch,indexing,delegates,nest,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

我正在.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()));
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Data.Linq;
使用System.Xml.Linq;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
利用鸟巢;
使用Newtonsoft.Json;
使用System.Data.Entity;
名称空间弹性控制台
{
班级计划
{
公共静态Uri节点;
公共静态连接设置;
公共静态弹性客户端;
静态void Main(字符串[]参数)
{
节点=新Uri(“http://localhost:9200");
设置=新连接设置(节点);
客户端=新的ElasticClient(设置);
DefaultIndex(“我的博客”);
var indexSettings=新的indexSettings();
indexSettings.NumberOfReplicas=1;
indexSettings.NumberOfShards=1;
CreateIndex(c=>c
.Index(“我的博客”)
.初始化(索引设置)
.AddMapping(m=>m.MapFromAttributes());
}
}
}
但它不起作用,我得到了这个错误:

错误CS1660无法将lambda表达式转换为类型“IndexName”,因为它不是委托类型

在生产线上:

client.CreateIndex(c => c
                    .Index("my_blog")
                    .InitializeUsing(indexSettings)
                    .AddMapping<Post>(m => m.MapFromAttributes()));
client.CreateIndex(c=>c
.Index(“我的博客”)
.初始化(索引设置)
.AddMapping(m=>m.MapFromAttributes());
我曾尝试在谷歌上搜索,但我只得到旧版本的帮助

提前感谢。

Uri节点=新的Uri(ES\u地址);
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);
var设置=新连接设置(节点); settings.DisableDirectStreaming()//检查json var客户端=新的ElasticClient(设置); //分析仪: CustomAnalyzer木瓦=新CustomAnalyzer { 标记器=“标准”, 过滤器=新列表() { “标准”、“小写”、“木瓦” } }; //索引的设置: var mapperTemplate=new CreateIndexDescriptor(string.Format(“客户”)) .Settings(s=>s .分析(a=>a .分析仪(an=>an .UserDefined(“分析仪面板”,面板) ) ) ); var customer=mapperTemplate.Mappings(ms=>ms .Map(m=>m .AllField(a=>a.Analyzer(“Analyzer_瓦”)) .AutoMap() ) ); //创建索引: var response=client.CreateIndex(客户);
您正在尝试使用新ElasticSearch Nest的旧方法。 您的代码将与NEST Ver一起使用。1.X。
更新新版本的代码,也可以使用旧版本的NEST。

对于最新版本,此snipet可以工作:

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

这看起来像NEST 1.x API,与NEST 2.x略有不同。你可以在elastic网站上找到Nest2.x的文档:耶!非常感谢你@俄罗斯骗局