弹性搜索升级2.3.1 Nest客户端Raw String [英] Elasticsearch upgrade 2.3.1 Nest client Raw String
问题描述
在升级到弹性2.3.1时,我正在使用.Net Nest Client进行阻止。
在Nest 1.0中,我可以从使用原始字符串配置创建索引。有没有一种方法可以与Nest 2.0类似,或者我必须为每个设置(包括分析部分)使用流畅的API?对于映射,同样的问题。
Nest 1.0
private bool CreateIndex (string index,FileInfo settingsFile)
{
var settings = File.ReadAllText(settingsFile.FullName);
IElasticsearchConnector _elastic
var response = _elastic.Client.Raw.IndicesCreate(index,settings);
if(!response.IsValid)
{
//记录错误
return false
}
return true;
}
ElasticClient.Raw
已重命名为 ElasticClient.LowLevel
。
这就是你可以在NEST 2.x中撰写您的请求。
_elastic.Client.LowLevel.IndicesCreate< object>(indexName,File.ReadAllText ( index.json));
内容 index.json
文件:
{
/ pre>
settings:{
index:{
number_of_shards 1,
number_of_replicas:1
},
分析:{
analyzer:{
analyzer-name:{
bb
过滤器 bmappings:{
employeeinfo:{
properties:{
age:{
type:long
}
experienceInYears:{
type:long
},
name:{
type:string,
a nalyzer:analyzer-name
}
}
}
}
}
}
希望有帮助。
While upgrading to elastic 2.3.1 I am running into a snag with the .Net Nest Client.
In Nest 1.0, I could read an index's settings from a file and configure the index on creation using the raw string. Is there a way to the something similar in Nest 2.0 or do I have to use the fluent API for each setting including the analysis portion? The same question for mappings.
Nest 1.0
private bool CreateIndex(string index, FileInfo settingsFile) { var settings = File.ReadAllText(settingsFile.FullName); IElasticsearchConnector _elastic var response = _elastic.Client.Raw.IndicesCreate(index, settings); if (!response.IsValid) { //Logging error return false } return true; }
解决方案
ElasticClient.Raw
has been renamed toElasticClient.LowLevel
.This is how you can compose your request in NEST 2.x.
_elastic.Client.LowLevel.IndicesCreate<object>(indexName, File.ReadAllText("index.json"));
Content of
index.json
file:{ "settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 1 }, "analysis" : { "analyzer" : { "analyzer-name" : { "type" : "custom", "tokenizer" : "keyword", "filter" : "lowercase" } } }, "mappings" : { "employeeinfo" : { "properties" : { "age" : { "type" : "long" }, "experienceInYears" : { "type" : "long" }, "name" : { "type" : "string", "analyzer" : "analyzer-name" } } } } } }
Hope it helps.
这篇关于弹性搜索升级2.3.1 Nest客户端Raw String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!