从java开始弹性搜索实例? [英] starting elasticsearch instance from java?

查看:130
本文介绍了从java开始弹性搜索实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java管理弹性搜索的开始和停止。有没有任何简单/好的方法来实现?



我们正在尝试在我们的产品中部署ElasticSearch,我们希望在客户机器上维护ElasticSearch的实例在我们自己的产品中,现在每件事情都取决于从es.bat或某些东西开始的ElasticSearch实例。



除此之外,任何人都可以给我一个例子如何模拟测试Jest API中的一些代码,用于ElasticSearch,所以我可以单元测试我们调用ElasticSearch的东西,而不需要启动一个ElasticSearch实例。

解决方案

启动弹性搜索实例是非常容易的。您只需使用 Java API 。这意味着你必须添加弹性搜索依赖项到你的项目并创建一个节点,如参考

  //启动时
Node node = nodeBuilder()。node );
客户端客户端= node.client();

// on shutdown
node.close();

创建节点后,它将与从命令行启动的节点的行为完全相同。您可以使用创建的客户端对象与其进行交互,但默认情况下,它还将打开9200和9300(或如果忙),则休眠呼叫和节点间通信的端口。


I want to manage starting and stopping of elasticsearch from Java. Is there any easy/nice way to do this?

We're trying to deploy ElasticSearch in our product and we want to maintain the instance of the ElasticSearch on our customer's machine in our own product, and right now every thing depends on having an ElasticSearch instance started from es.bat or something.

As an aside, can anyone give me an example of how to mock test some code around the Jest API for ElasticSearch, so I can unit test our stuff that calls ElasticSearch without needing to start an ElasticSearch instance?

解决方案

Starting an elasticsearch instance is extermely easy. You just have to use the Java API. That means you have to add the elasticsearch dependency to your project and create a node, as mentioned in the reference:

// on startup
Node node = nodeBuilder().node();
Client client = node.client();

// on shutdown
node.close();

Once you created the node it will behave exactly the same as a node started from the command line. You can interact with it using the created client object, but by default it will also open the 9200 and 9300 (or following ones if busy) ports for rest calls and inter-node communication.

这篇关于从java开始弹性搜索实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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