在Solr中,如何获取所有文档的一个字段(文档ID)的列表?

cwd*_*cwd 2 lucene oracle indexing solr

我正在使用从oracle数据库填充的Solr实例.当从oracle数据库添加和删除记录时,它们也应该从Solr中添加和删除.

schema.xml具有这种设置,我们用它来存储,这也是Oracle中的主键ID:

<uniqueKey>id</uniqueKey>
<field name="id" type="string" indexed="true" stored="true"/>
Run Code Online (Sandbox Code Playgroud)

此外,ID不是按顺序排列的.solr管理界面没有多大帮助,我只能看到ID以及每个记录的其余部分,一次一些,分页.

此solr核心中有大约一百万个文档.

我可以很容易地从oracle数据库中获取记录的ID,因此我还希望id从solr索引中获取文档列表以进行比较.

我无法找到有关如何执行此操作的任何信息,但我可能正在搜索

Syl*_*oux 6

如果您确实需要获取所有文档的ID,请使用参数.这样的东西:fl

SolrQuery q = new SolrQuery("*:*&fl=id");
//                               ^^^^^
//                          return only the `id` field
q.setRows(10000000);
//        ^^^^^^^^
// insanely high number: retrieve _all_ rows
// see: http://wiki.apache.org/solr/CommonQueryParameters#rows-1
return server.query(q).getResults();
Run Code Online (Sandbox Code Playgroud)

(未经测试):


要简单比较Oracle和Solr中的内容,您可能只想计算文档:

SolrQuery q = new SolrQuery("*:*");
q.setRows(0);
//        ^
// don't retrieve _any_ row
return server.query(q).getResults().getNumFound();
//                                  ^^^^^^^^^^^^^
//                             just get the number of matching documents
Run Code Online (Sandbox Code Playgroud)

(未经测试):