【问题标题】:Read ElasticSearch Index from Java从 Java 中读取 ElasticSearch 索引
【发布时间】:2015-08-10 09:31:48
【问题描述】:

我正在尝试从 Java 程序中读取 ElasticSearch (1.4) 索引,但我真的不知道从哪里开始。

我没有正在运行的 ES 实例,因此我无法使用“普通”API。

据我了解,实际索引文件是 Lucene,因此必须有一种读取它们的方法。性能不是问题,所以我不介意程序运行时间长一点(甚至整晚)。

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    是的,你说得对 Elasticsearch 索引(在一个分片上)只是一个普通的 Lucene 索引,所以使用 在 Java 程序中打开它真的很容易Lucene.

    最简单的方法如下:

    IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(INDEX_PATH)));
    IndexSearcher searcher = new IndexSearcher(reader);
    

    它是 Lucene 5.0,但 Lucene 4.xx 会与此类似:

    IndexReader reader = IndexReader.open(FSDirectory.open(new File(INDEX_PATH)), true);
    IndexSearcher searcher = new IndexSearcher(reader);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2023-03-20
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多