使用NEST V5.4重新编制索引 - ElasticSearch [英] Reindexing using NEST V5.4 - ElasticSearch
问题描述
我对ElasticSearch很新。我正在尝试重新索引索引以重命名它。我正在使用NEST API v5.4。
我看到了这个例子:
I'm quite new to ElasticSearch. I'm trying to reindex a index in order to rename it. I'm using NEST API v5.4. I saw this example:
var reindex =
elasticClient.Reindex<Customer>(r =>
r.FromIndex("customers-v1")
.ToIndex("customers-v2")
.Query(q => q.MatchAll())
.Scroll("10s")
.CreateIndex(i =>
i.AddMapping<Customer>(m =>
m.Properties(p =>
p.String(n => n.Name(name => name.Zipcode).Index(FieldIndexOption.not_analyzed))))));
来源: http://thomasardal.com/elasticsearch-migrations-with-c-and-nest/
但是,我无法使用NEST 5.4重现这一点。我认为这是2.4版本。
我检查ElasticSearch的重大变化并尝试使用以下方法重新编制索引:
However, I can't reproduce this using NEST 5.4. I think that is to version 2.4. I check the breaking changes of ElasticSearch and try reindexing using this:
来源: https://www.elastic.co/guide/en/elasticsearch /client/net-api/current/nest-breaking-changes.html
public method Nest.ReindexDescriptor..ctor Declaration changed (Breaking)
2.x: public .ctor(IndexName from, IndexName to) 5.x: public .ctor()
var reindex = new client.Reindex(oldIndexName, newIndexName);
但这也不起作用。
我也搜索文档,但我没有在c#上找到任何代码,只是JSON
来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html )
But this did not work too. I also search for documentation but i didn't find any code on c#, just JSON Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
有人能举例说明如何在C#上使用NEST 5.4重新索引吗?
提前致谢! :slight_smile:
Thanks in advance! :slight_smile:
推荐答案
搜索了2天后,我找到了重新索引索引的解决方案。为了解决未来的问题,我将提供我的解决方案。
After search for 2 long days I found out the solution to reindex a index. In order to solve future problems, I'll provide my solution.
Nest版本 - 5.4
Nest Version - 5.4
var reindex = client.Reindex<object>(r => r
.BackPressureFactor(10)
// ScrollAll - Scroll all the documents of the index and store it for 1minute
.ScrollAll("1m", 2, s => s
.Search(ss => ss
.Index(oldIndexName)
.AllTypes())
// there needs to be some degree of parallelism for this to work
.MaxDegreeOfParallelism(4))
.CreateIndex(c => c
// New index here
.Index(newIndexName)
.Settings(
// settings goes here)
.Mappings(
// mappings goes here))
.BulkAll(b => b
// New index here!
.Index(newIndexName)
.Size(100)
.MaxDegreeOfParallelism(2)
.RefreshOnCompleted()));
ReIndex方法返回一个冷 IObservable ,你必须在其上调用。订阅()以启动所有内容。
the ReIndex method returns a cold IObservable on which you have to call .Subscribe() to kick off everything.
因此,您需要将其添加到您的代码中:
So, you need to add it to your code:
var o = new ReindexObserver(
onError: (e) => { //do something },
onCompleted: () => { //do something });
reindex.Subscribe(o);
检查此信息的有用链接是:
这篇关于使用NEST V5.4重新编制索引 - ElasticSearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!