NEST弹性搜索Reindex示例

NEST弹性搜索Reindex示例

本文介绍了NEST弹性搜索Reindex示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的目标是使用1000万个分片重新索引索引,以改变字段映射,以便进行重要的术语分析。我的问题是我遇到麻烦使用NEST库执行重新索引,文档(非常)受限制。如果可能,我需要使用以下的例子:





解决方案

NEST提供了一个不错的 Reindex 方法,尽管文档不足。我已经用这个特殊的WinForms代码,以非常粗糙和准备的方式使用它。

  private ElasticClient客户端; 
私人双数;

private void reindex_Completed()
{
MessageBox.Show(Done!);
}

private void reindex_Next(IReindexResponse< object> obj)
{
count + = obj.BulkResponse.Items.Count();
var progress = 100 * count /(double)obj.SearchResponse.Total;
progressBar1.Value =(int)progress;
}

private void reindex_Error(Exception ex)
{
MessageBox.Show(ex.ToString());
}

private void button1_Click(object sender,EventArgs e)
{
count = 0;

var reindex = client.Reindex< object>(r => r.FromIndex(fromIndex.Text).NewIndexName(toIndex.Text).Scroll(10s));

var o = new ReindexObserver< object>(onError:reindex_Error,onNext:reindex_Next,completed:reindex_Completed);
reindex.Subscribe(o);
}

我刚刚发现了博客帖子,告诉我如何做:


my objective is to reindex an index with 10 million shards for the purposes of changing field mappings to facilitate significant terms analysis.

My problem is that I am having trouble using the NEST library to perform a re-index, and the documentation is (very) limited. If possible I need an example of the following in use:

http://nest.azurewebsites.net/nest/search/scroll.html

http://nest.azurewebsites.net/nest/core/bulk.html

解决方案

NEST provides a nice Reindex method you can use, although the documentation is lacking. I've used it in a very rough-and-ready fashion with this ad-hoc WinForms code.

    private ElasticClient client;
    private double count;

    private void reindex_Completed()
    {
        MessageBox.Show("Done!");
    }

    private void reindex_Next(IReindexResponse<object> obj)
    {
        count += obj.BulkResponse.Items.Count();
        var progress = 100 * count / (double)obj.SearchResponse.Total;
        progressBar1.Value = (int)progress;
    }

    private void reindex_Error(Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }

    private void button1_Click(object sender, EventArgs e)
    {
        count = 0;

        var reindex = client.Reindex<object>(r => r.FromIndex(fromIndex.Text).NewIndexName(toIndex.Text).Scroll("10s"));

        var o = new ReindexObserver<object>(onError: reindex_Error, onNext: reindex_Next, completed: reindex_Completed);
        reindex.Subscribe(o);
    }

And I've just found the blog post that showed me how to do it: http://thomasardal.com/elasticsearch-migrations-with-c-and-nest/

这篇关于NEST弹性搜索Reindex示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:36