简体   繁体   English

ElasticSearch 中的索引映射请求使用 C# 中的 NEST

[英]Index mapping request in ElasticSearch using NEST in C#

I need to create an index with mapping using a json string provided from the input.我需要使用从输入提供的 json 字符串创建一个带有映射的索引。 I am trying to pass the json mapping string in a lowlevel client since my usecase has a long list of mappings which I can not do using a high-level client.我正在尝试在低级客户端中传递 json 映射字符串,因为我的用例有很长的映射列表,而使用高级客户端则无法做到。 However, it is creating a null mapping with the lowlevel client I am using.但是,它正在使用我正在使用的低级客户端创建 null 映射。 Below is a simple example of my mapping json string.下面是我映射 json 字符串的简单示例。

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

Below is the code snippet which I am using to create an index and then lowlevel request to create the mapping.下面是我用来创建索引的代码片段,然后是创建映射的低级请求。

        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));

Any help or suggestion is greatly appreciated.非常感谢任何帮助或建议。

The mapping string JSON format is not correct for an Update Mapping API call . 对于更新映射 API 调用,映射字符串 JSON 格式不正确 It's closer to the format used when creating an index with a mapping, but still not correct .更接近于使用映射创建索引时使用的格式, 但仍然不正确

To make a call with the low level client to create an index and mapping at the same time调用低级客户端同时创建索引和映射

var client = new ElasticClient();

var IndexName = "my-index";

var request = @"{
    ""mappings"": {
        ""properties"": {
            ""exchangeid"": { ""type"": ""double"" }
        }
    }
}";

var response = client.LowLevel.Indices.Create<StringResponse>(IndexName, request);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM