簡體   English   中英

在NEST 2.3.1中創建索引時出錯(彈性搜索)

[英]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()));
        }
    }
}

但它沒有用,我收到了這個錯誤:

錯誤CS1660無法將lambda表達式轉換為類型'IndexName',因為它不是委托類型

在線:

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。

在最后一個版本中,這個snipet工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM