2016-05-24 2 views
1

.NETプロジェクトでNEST 2.3.1を使用しています。NEST 2.3.1(Elastic Search)でインデックスを作成する際にエラーが発生しました

私は非常に新しいです。

私はこのチュートリアルを見たので、私はこのコードを実行しました。

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で検索しようとしているが、私は唯一取得しています古いバージョンのヘルプ!

ありがとうございました。

+0

これは、NEST 2.xのは若干異なるNEST 1.xのAPIのように見えますNEST 2.xのドキュメントは、エラスティックサイトで見つけることができます:https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/index.html –

+0

うん!どうもありがとうございます! @RussCam –

答えて

2

新しいElasticSearch Nestで古い方法を試しています。 あなたのコードはNEST Verで動作します。 1.X。 新しいバージョンのコードを更新するか、古いバージョンのNESTを使用できます。このsnipet作品最後のバージョンと

+0

NEST 1.xを試してみましたが、動作しています。 –

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

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

それは、感謝の仲間が動作します。 – nsarchar

関連する問題