在没有搜索的情况下从Solr读取所有文档(仅在可能的情况下为doc id)


v-star*위위
2025-03-13 01:47:17 (26天前)


我知道Solr意在用于搜索。

但是,我正在做一些基准测试,我想知道是否有办法检索索引的每个文档的文档ID。

最好的选择是检索……

2 条回复
  1. 0# v-star*위위 | 2019-08-31 10-32



    使用

    /export

    终点:

    导出结果集




    它支持使用相同的

    fl

    参数作为常规搜索(尽管只搜索

    :

    当你使用SolrJ时,它可能会表现得非常相似。



    在SolrJ你必须使用

    CloudSolrStream

    而不是正确地传输结果(与搜索时的常规行为相比)

    :

    )。





    Joel Bernstein在介绍这个特征时的例子





    1. import org.apache.solr.client.solrj.io.;
      import java.util.
      ;

    2. public class StreamingClient {

    3. public static void main(String args[]) throws IOException {
      String zkHost = args[0];
      String collection = args[1];

    4.   Map props = new HashMap();
    5.   props.put("q", "*:*");
    6.   props.put("qt", "/export");
    7.   props.put("sort", "fieldA asc");
    8.   props.put("fl", "fieldA,fieldB,fieldC");
    9.   CloudSolrStream cstream = new CloudSolrStream(zkHost, 
    10.                                                 collection, 
    11.                                                 props);
    12.   try {
    13.     cstream.open();
    14.     while(true) {
    15.       Tuple tuple = cstream.read();
    16.       if(tuple.EOF) {
    17.          break;
    18.       }
    19.       String fieldA = tuple.getString("fieldA");
    20.       String fieldB = tuple.getString("fieldB");
    21.       String fieldC = tuple.getString("fieldC");
    22.       System.out.println(fieldA + ", " + fieldB + ", " + fieldC);
    23.     }
    24.   } finally {
    25.    cstream.close();
    26.   }
    27. }
      }

    28. </code>

登录 后才能参与评论