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

nest : how do an index mapping by passing a raw request?

我想通过 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);

你知道是否可以直接给elasticsearch请求做映射?

是的,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);