2016-07-01 4 views
0

以下のコードを実行すると、必要のないすべてのインデックスにマッピングが作成されます。私が望むインデックスだけを指定するためのドキュメントを見つけることができません。
このマッピングを適用するインデックスを指定する方法を教えてください。NESTを使用してElasticsearchのインデックスを指定するにはどうすればよいですか?

var client = new ElasticClient(); 
var response = client.Map<Company>(m => m 
    .Properties(props => props 
     .Number(n => n 
      .Name(p => p.ID) 
      .Type(NumberType.Integer) 
     ) 
    ) 
); 

答えて

4

これは、既存のインデックスにマッピングを置くプット・マッピング記述子に

var response = client.Map<Company>(m => m 
    .Index("index-name") 
    .Properties(props => props 
     .Number(n => n 
      .Name(p => p.ID) 
      .Type(NumberType.Integer) 
     ) 
    ) 
); 

.Index()を追加します。索引がまだ存在しない場合は、索引を作成し、1回の要求でその索引のマッピングを定義できます。たとえば、

var createIndexResponse = client.CreateIndex("index-name", c => c 
    // settings for the index 
    .Settings(s => s 
     .NumberOfShards(3) 
     .NumberOfReplicas(1) 
     .RefreshInterval("5s") 
    ) 
    // mappings for the index 
    .Mappings(m => m 
     .Map<Company>(mc => mc 
      .Properties(props => props 
       .Number(n => n 
        .Name(p => p.ID) 
        .Type(NumberType.Integer) 
       ) 
      ) 
     ) 
    ) 
); 
0

このようなこともあります。

 string IndexName = "my_index"; 
     this.client.CreateIndex(IndexName, c => 
      c.AddMapping<CForm> 
      (m => m.Properties(ps => ps.Attachment 
            (a => a.Name(o => o.Document) 
              .TitleField(t => t.Name(x => x.Name) 
                  .TermVector(TermVectorOption.WithPositionsOffsets)))))); 


     // Create Mappings for the fields with specific properties. 
     // You can also make field1 a multi-field and make it both analyzed and not_analyzed 
     // to get the best of both worlds (i.e. text matching on the analyzed field + aggregation on the exact value 
     // of the not_analyzed raw sub-field). 

     // Field: Plan 
     var result = this.client.Map<CForm>(m => m 
      .Properties(props => props 
       .MultiField(s => s 
        .Name(p => p.Plan) 
        .Fields(pprops => pprops 
           .String(ps => ps.Name(p => p.Plan).Index(FieldIndexOption.NotAnalyzed)) 
           .String(ps => ps.Name("original").Index(FieldIndexOption.Analyzed)) 
         ) 
        ) 
       ) 
      ); 
関連する問題