我将我的Nest和Elastic Search NuGet包从1.7.1升级到2.4.6。一切似乎都工作正常,但我担心的一件事是我创建索引的地方。
我曾经在旧的1.x世界中设置了两个设置,我无法弄清楚如何设置2.x世界。创建一个索引来自:
ixSettings.NumberOfReplicas = 1;
ixSettings.NumberOfShards = 5;
ixSettings.Settings.Add("merge.policy.merge_factor", "10");
ixSettings.Settings.Add("search.slowlog.threshold.fetch.warn", "1s");
EsClient.CreateIndex(c => c
.Index(ES_Index)
.InitializeUsing(ixSettings)
);
到此:
EsClient.CreateIndex(ES_Index, c => c
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(5)));
var mapResponse = EsClient.Map<WebPage>(m => m.AutoMap()); //apply the index mapping
我认为合并策略和获取警告设置是我从Elastic Search“入门指南”中获得的。 “merge_factor”默认为10,所以这没关系,我猜“search.slowlog.threshold.fetch.warn”是一个日志记录的东西。
我的问题是:
答案 0 :(得分:2)
索引创建时的设置已得到改进,可为索引创建时允许的设置提供流畅的API和Object Initializer语法。
您可以使用.Setting()
client.CreateIndex("index-name", c => c
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(5)
.Setting("merge.policy.merge_factor", "10")
.Setting("search.slowlog.threshold.fetch.warn", "1s")
)
);
但应注意 merge.policy.merge_factor
is removed from Elasticsearch 2.0+。您可以找到
client.CreateIndex("index-name", c => c
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(5)
.Merge(m => m
.Policy(mp => mp
. // See which settings are available here
)
)
)
);
同样,可以使用
设置search.slowlog.threshold.fetch.warn
client.CreateIndex("index-name", c => c
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(5)
.SlowLog(sl => sl
.Search(ssl => ssl
.Fetch(f => f
.ThresholdWarn("1s")
)
)
)
)
);
产生以下请求:
PUT http://localhost:9200/index-name
{
"settings": {
"index.number_of_replicas": 1,
"index.search.slowlog.threshold.fetch.warn": "1s",
"index.number_of_shards": 5
}
}