SolrCloud重新索引路由问题

时间:2015-08-10 13:51:32

标签: solr solrj solrcloud

我正在将SolrCloud从版本4.8.1更新到版本5.2.1,我知道在这些情况下建议使用完整的重新索引。不幸的是,在我的情况下,执行它的唯一方法是使用我当前的索引作为数据源,通过从当前集合中读取文档并在新集合中重新索引它们。我知道这不是建议的过程,但我真的没有任何其他方法来执行完整的重新索引。 所以,我构建了自己的java代码来自动执行这个过程。这里是伪代码:

CloudSolrClient serverOutput = new CloudSolrClient(...);
serverOutput.setDefaultCollection(...);
List<SolrInputDocument> buffer = new ArrayList<>(bufferSize);
int currentIndex = 0;
int totalNumberOfDocs = ...;
while (currentIndex < totalNumberOfDocs) {
        SolrDocumentList solrDocumentList = getChunkOfSolrDocument(currentIndex); //this returns a chunk of documents from my old collection
        currentIndex += solrDocumentList.size();

        for(int i=0; i < solrDocumentList.size(); i++){
            SolrDocument solrDoc = solrDocumentList.get(i);
            SolrInputDocument solrInputDoc = org.apache.solr.client.solrj.util.ClientUtils.toSolrInputDocument(solrDoc);
            solrInputDoc.removeField("_version_");
            buffer.add(solrInputDoc);
        }

    if (buffer.size() > bufferSize) {
        try {
            for (SolrInputDocument doc : buffer) {
                serverOutput.add(doc);
            }
            serverOutput.commit();
        } catch (Exception e) {
            ...
        } finally {
            buffer.clear();
        }
    }
}

if (!buffer.isEmpty()) {
    try {
        for (SolrInputDocument doc : buffer) {
            serverOutput.add(doc);
        }
        serverOutput.commit();
    } catch (Exception e) {
        ...
    } finally {
        buffer.clear();
    }
}

我的旧系列和新系列都使用Solr Cloud compositeId路由器。我的旧系列有4个碎片,而新系列有16个碎片。旧集合具有以下哈希范围:

  "shard1" ==> "range":"80000000-bfffffff",
  "shard2" ==> "range":"c0000000-ffffffff",
  "shard3" ==> "range":"0-3fffffff",
  "shard4" ==> "range":"40000000-7fffffff"

新集合具有以下哈希范围:

  "shard1" ==> "range":"80000000-8fffffff",
  "shard2" ==> "range":"90000000-9fffffff",
  "shard3" ==> "range":"a0000000-afffffff",
  "shard4" ==> "range":"b0000000-bfffffff",
  "shard5" ==> "range":"c0000000-cfffffff",
  "shard6" ==> "range":"d0000000-dfffffff",
  "shard7" ==> "range":"e0000000-efffffff",
  "shard8" ==> "range":"f0000000-ffffffff",
  "shard9" ==> "range":"0-fffffff",
  "shard10" ==> "range":"10000000-1fffffff",
  "shard11" ==> "range":"20000000-2fffffff",
  "shard12" ==> "range":"30000000-3fffffff",
  "shard13" ==> "range":"40000000-4fffffff",
  "shard14" ==> "range":"50000000-5fffffff",
  "shard15" ==> "range":"60000000-6fffffff",
  "shard16" ==> "range":"70000000-7fffffff"

此代码可以在新集合中成功导入我的文档,但由于某种原因,它只在我的16-shards集合的4个分片中导入文档。因此,在流程结束时,我的新集合包含与旧集合相同的文档,但我的新集合中有4个文档碎片和12个碎片空白。

我还尝试使用字段的“白名单”,指定我在模式中使用的相同字段,为任何其他字段执行solrInputDoc.removeField但我有相同的结果。我甚至试图创建一个空的4个分片集合,仔细检查两个集合中的哈希范围是否相同,然后分割分片,直到我有16个分片,然后删除“原始”分片和运行我的代码:我仍然有4个分片填充,12个分片为空。

你知道为什么文件没有在所有16个分片中正确分发吗?

非常感谢你们。

编辑:我的所有字段都 stored =“true”

EDIT2 :如果您希望将所有细分更新为Lucene更新版本的文件格式,那么优化您的索引就足够了。但是,我仍然想解决这个“路由”问题,因为它可以解决this open bug

0 个答案:

没有答案
相关问题