2016-05-02 15 views
0

私は、インデックスと
を解析を使用したいのC#(巣)Elasticsearch.netインデックスの設定+アナライザ

とelasticsearch 2.3.0バージョンを使用することができますが、インデックスの設定は変更されませんし、私はそうではありません理由を知っている。 ここに私のコードです:

 private void button1_Click_1(object sender, EventArgs e) 
      { 
      var conn = new Uri("http://localhost:9200"); 
      var config = new ConnectionSettings(conn); 
      var client = new ElasticClient(config); 
      string server = cmb_Serv.Text.Trim(); 
     if (server.Length > 0) 
    { 
      string ser = server; 
      string uid = util.getConfigValue("SetUid"); 
      string pwd = util.getConfigValue("SetPwd"); 
      string dbn = cmb_Db.Text; 
      string tbl = cmb_Tbl.Text; 
      setWorkDbConnection(ser, uid, pwd, dbn); 

      string query = util.getConfigValue("SelectMC"); 
      query = query.Replace("###tbl###",tbl); 

      using (SqlCommand cmd1 = new SqlCommand()) 
      { 
       using (SqlConnection con1 = new SqlConnection()) 
       { 
        con1.ConnectionString = util.WorkConnectionString; 
        con1.Open(); 
        cmd1.CommandTimeout = 0; cmd1.Connection = con1; 
        cmd1.CommandText = query; 

        int id_num =0; 

        SqlDataReader reader = cmd1.ExecuteReader(); 
        while (reader.Read()) 
        { id_num++; 

        Console.Write("\r" + id_num); 

         var mc = new mc 
         { 
          Id = id_num, 
          code = reader[0].ToString(), 
          mainclass = reader[1].ToString().Trim() 
         }; 
         client.Index(mc, idx => idx.Index("mctest_ilhee")); 
        client.Alias(x => x.Add(a =>   a.Alias("mcAlias").Index("mctest_ilhee"))); 
         client.Map<mc>(d => d 
          .Properties(props => props 
          .String(s => s 
          .Name(p => p.mainclass) 
          .Name(p2 => p2.code).Index(FieldIndexOption.Analyzed).Analyzer("whitespace")))); 



        } reader.Dispose(); 
        reader.Close(); 

       } 
       IndexSettings Is = new IndexSettings(); 
       Is.Analysis.Analyzers.Add("snowball", new SnowballAnalyzer()); 
       Is.Analysis.Analyzers.Add("whitespace", new WhitespaceAnalyzer()); 
      } 
     } 
    } 

答えて

1

まず最初にあなたのコードは変です。 中にマッピングを行う理由は何ですか?マッピングは1回だけ行います。 あなたが得るエラーさえ提供していないので、あなたを助けることは不可能です。私は単純なデバッグ方法を追加することをお勧めします。

protected void ValidateResponse(IResponse response) 
{ 
    if (!response.IsValid || 
    (response is IIndicesOperationResponse && !((IIndicesOperationResponse) response).Acknowledged)) 
    { 
     var error = string.Format("Request to ES failed with error: {0} ", response.ServerError != null ? response.ServerError.Error : "Unknown"); 
     var esRequest = string.Format("URL: {0}\n Method: {1}\n Request: {2}\n", 
        response.ConnectionStatus.RequestUrl, 
        response.ConnectionStatus.RequestMethod, 
        response.ConnectionStatus.Request != null 
         ? Encoding.UTF8.GetString(response.ConnectionStatus.Request) 
         : string.Empty); 
    } 
} 

client.Alias、ステータスを返しclient.Mapとしてすべての要求。だから、あなたは二つのこと、ES

に送信するNEST +要求を返しES propperエラーが表示されます

var result = client.Map<mc>(.....YOUR_CODE_HERE....) 
ValidateResponse(result); 

を行うことができます

関連する問題