【问题标题】:How to read from ES 1.7 of huge data to index into ES 6.7如何从 ES 1.7 读取大量数据以索引到 ES 6.7
【发布时间】:2019-05-08 13:46:24
【问题描述】:

需要从 ES 1.7 读取数据以索引到 6.7。 因为没有可用的升级。需要索引 2 亿条记录的近 5 TB 数据。我们使用搜索和滚动方法使用 ES_REST_high_level_client(6.7.2)。但无法使用滚动 ID 滚动。另一种尝试的方法是使用 from 和 batch size。最初读取速度更快,因为从偏移量增加读取真的很糟糕。最好的方法是什么。

第一种使用搜索和滚动的方法。

            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.size(10);
            searchRequest.source(searchSourceBuilder);
            searchRequest.scroll(TimeValue.timeValueMinutes(2));
            SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
            String scrollId = searchResponse.getScrollId();

    while (run) {
                SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
                scrollRequest.scroll(TimeValue.timeValueSeconds(60));
                SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
                scrollId = searchScrollResponse.getScrollId();
                hits = searchScrollResponse.getHits();

                if (hits.getHits().length == 0) {
                    run = false;
                }
            }

例外 线程“主”中的异常 ElasticsearchStatusException [Elasticsearch 异常 [type=exception, reason=ElasticsearchIllegalArgumentException[Failed to decode scrollId];嵌套:IOException[Bad Base64 input character decimal 123 in array position 0]; ]] 在 org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) 在 org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2050) 在 org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:2026) :

第二种方法:

int offset = 0;
        boolean run = true;
        while (run) {
            SearchRequest searchRequest = new SearchRequest("indexname");
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.from(offset);
            searchSourceBuilder.size(500);
            searchRequest.source(searchSourceBuilder);
            long start = System.currentTimeMillis();
            SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
            long end = System.currentTimeMillis();

            SearchHits hits = searchResponse.getHits();
            System.out.println(" Total hits : " + hits.totalHits + " time : " + (end - start));
            offset += 500;
            if(hits.getHits().length == 0) {
                run = false;
            }
        }

任何其他读取数据的方法。

【问题讨论】:

  • 1) 对数据进行逻辑切片(例如按日期)然后 2) 使用带有弹性搜索输入和弹性搜索输出的 logstash?
  • 读取仍然很昂贵..索引变得非常大..现在切片索引有点困难..因为我们在 1.7 ES 版本中..
  • 我对切片的建议与版本无关,你会做多个并行查询,每个查询都有自己的日期范围。

标签: java elasticsearch elastic-stack elasticsearch-jest


【解决方案1】:

通常最好的解决方案是远程重新索引:https://www.elastic.co/guide/en/elasticsearch/reference/6.7/docs-reindex.html#reindex-from-remote

我不确定 REST 客户端是否仍然与 1.x 兼容,而远程重新索引应该支持它。

深度分页非常昂贵,这就是为什么应该避免它——你会在你的例子中看到原因。

【讨论】:

  • 它不起作用,因为版本是旧索引:) 我们想在文档中过滤和更新。
  • 远程重新索引从 1.7 到 6.x 应该 IMO 仍然有效。这支持过滤,您可以使用脚本更新您的文档。将类型更改为 _doc 将是我现在要清理的内容,以使升级到 7 更简单
猜你喜欢
  • 2017-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
  • 2014-09-10
  • 2013-09-14
  • 1970-01-01
相关资源
最近更新 更多