1
在我的ElasticSearch服务器中,我有一个现有的索引模板,其中包含一些设置和一些映射。将映射添加到现有索引模板(使用NEST属性)
我想为模板添加新类型的映射,但由于无法更新模板,我需要删除现有模板并重新创建它。
因为我想保留所有现有的设置,我试图让现有的定义,在这个例子中,映射添加到它,然后删除/重建,如:
using Nest;
using System;
public class SomeNewType {
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string SomeField { get; set; }
[ElasticProperty(Index = FieldIndexOption.Analyzed)]
public string AnotherField { get; set; }
}
class Program {
static void Main(string[] args) {
var settings = new ConnectionSettings(uri: new Uri("http://localhost:9200/"));
var client = new ElasticClient(settings);
var templateResponse = client.GetTemplate("sometemplate");
var template = templateResponse.TemplateMapping;
client.DeleteTemplate("sometemplate");
// Add a mapping to the template somehow...
template.Mappings.Add(...);
var putTemplateRequest = new PutTemplateRequest("sometemplate") {
TemplateMapping = template
};
client.PutTemplate(putTemplateRequest);
}
}
但是,我无法找到一种方法来映射添加使用ElasticProperty模板定义属性,如在
client.Map<SomeNewType>(m => m.MapFromAttributes());
是否有可能创建一个RootObjectMapping
添加到收藏Mappings
类似于东西?
谢谢,这正是我所需要的。关于删除,即使我删除模板,它看起来仍然保留设置:毕竟,GET _template'请求也返回设置,对吧? –