【问题标题】:Index mapping request in ElasticSearch using NEST in C#在 C# 中使用 NEST 在 ElasticSearch 中的索引映射请求
【发布时间】:2021-04-28 22:44:02
【问题描述】:

我需要使用输入提供的 json 字符串创建一个带有映射的索引。我正在尝试在低级客户端中传递 json 映射字符串,因为我的用例有很长的映射列表,而使用高级客户端则无法做到。但是,它正在使用我正在使用的低级客户端创建一个空映射。下面是我的映射 json 字符串的一个简单示例。

mappingString = {
"mappings" : {  
"exchangeid" : {
          "type" : "double"
        }
}

下面是我用来创建索引的代码 sn-p,然后是创建映射的低级请求。

        CreateIndexResponse createIndexResponse = ElasticAccessor.Client.Indices.Create(IndexName, c => c
        .InitializeUsing(indexConfig));

        // Put mapping request
        StringResponse putMappingRequest = ElasticAccessor.Client.LowLevel.DoRequest<StringResponse>(HttpMethod.PUT, 
            "/" + IndexName + "/_mapping", 
            PostData.String(this.mappingString));

非常感谢任何帮助或建议。

【问题讨论】:

    标签: c# .net elasticsearch nest


    【解决方案1】:

    映射字符串 JSON 格式为not correct for an Update Mapping API call。它更接近使用映射创建索引时使用的格式but still not correct

    调用低级客户端同时创建索引和映射

    var client = new ElasticClient();
    
    var IndexName = "my-index";
    
    var request = @"{
        ""mappings"": {
            ""properties"": {
                ""exchangeid"": { ""type"": ""double"" }
            }
        }
    }";
    
    var response = client.LowLevel.Indices.Create<StringResponse>(IndexName, request);
    
    

    【讨论】:

    • 非常感谢您的回复。映射的东西有效。但是,我想知道如何在这个低级客户端中附加 IndexSettings(例如 NumberOfReplicas = 1、NumberOfShards = 2 等)以及映射。我曾经在高级客户端中使用 indexConfig,如下所示。 CreateIndexResponse createIndexResponse = ElasticAccessor.Client.Indices.Create(IndexName, c => c .InitializeUsing(indexConfig));
    猜你喜欢
    • 2017-09-14
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多