2017-02-05 46 views
0

我想穿過巢,但通過我想直接獲得原料elasticsearch要求做索引的映射:巢:如何做一個索引映射通過傳遞原始請求?

var setting = new ConnectionSettings(new Uri("uri")); 
setting.DefaultIndex(_esIndexName); 
var client = new ElasticClient(setting); 

string rawEsRequest= "PUT /myindex 
{ 
    ""mappings"": { 
     ""review"": { 
     ""properties"": { 
      ""commentaire"": { 
      ""analyzer"" : ""french"", 
      ""type"": ""text"", 
      ""fields"": { 
       ""keyword"": { 
       ""type"": ""keyword"", 
       ""ignore_above"": 256 
       } 
      } 
      }, 
      ""date_creaation"": { 
      ""type": "date"" 
      } 
}}}}" 

//want to do this bellow 
client.Mapping.rawPut(rawEsRequest); 

你知道,如果有可能給做映射直接elasticsearch要求?

回答

3

是的,低級客戶端Elasticsearch.Net也暴露在NEST的高級客戶端通過.LowLevel屬性。您只需要刪除HTTP動詞和URI,因爲它們是客戶端上方法調用的一部分。

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); 
var defaultIndex = "myindex; 
var connectionSettings = new ConnectionSettings(pool) 
     .DefaultIndex(defaultIndex); 

var client = new ElasticClient(connectionSettings); 

string rawEsRequest = @"{ 
    ""mappings"": { 
     ""review"": { 
      ""properties"": { 
       ""commentaire"": { 
        ""analyzer"" : ""french"", 
     ""type"": ""text"", 
     ""fields"": { 
         ""keyword"": { 
          ""type"": ""keyword"", 
      ""ignore_above"": 256 
         } 
        } 
       }, 
       ""date_creaation"": { 
          ""type"": ""date"" 
       } 
      } 
     } 
    } 
}"; 

ElasticsearchResponse<dynamic> putResponse = 
    client.LowLevel.IndicesCreate<dynamic>(defaultIndex, rawEsRequest);