从Java读取ElasticSearch索引 [英] Read ElasticSearch Index from Java

查看:420
本文介绍了从Java读取ElasticSearch索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to read an ElasticSearch (1.4) index from a Java program, but I don't really have an idea where to start.

我没有正在运行的ES实例,因此无法使用常规" API.

I don't have a running ES instance so I cannot use the "normal" API.

我了解的是,acual索引文件是 Lucene ,因此必须有一种读取它们的方法.性能不是问题,因此我不介意程序运行时间更长(甚至整夜).

What I understand is the acual index files are Lucene so there must be a way to read them. Performance is not an issue, so I don't mind if the program runs a little longer (or even all night).

推荐答案

是的,您是正确的 Elasticsearch 索引(在一个分片上),只是正常的 Lucene 索引,因此使用 Lucene 在Java程序中打开它真的很容易.

Yes, you're right Elasticsearch index (on one shard) just a normal Lucene index, so it's really easy to open it in Java program using 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);

这篇关于从Java读取ElasticSearch索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆