nest:如何通过传递原始请求进行索引映射?

时间:2017-02-05 22:33:48

标签: elasticsearch nest

我想通过遍历nest进行索引映射,但是我想直接给出一个原始的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);

您是否知道是否可以提供直接弹性搜索请求进行映射?

1 个答案:

答案 0 :(得分:3)

是的,Elasticsearch.Net中的低级客户端也通过.LowLevel属性在NEST的高级客户端上公开。您只需要删除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);