Running elasticsearch instance from java?

I want to control starting and stopping elasticsearch with Java. Is there an easy / good way to do this?

We are trying to deploy ElasticSearch in our product, and we want to save an instance of ElasticSearch on our client machine in our own product, and now it all depends on whether the ElasticSearch instance started with es.bat or something else.

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

+7
java elasticsearch
source share
1 answer

Starting an elasticsearch instance is extremely simple. You just need to use the Java API . This means that you need to add an elasticsearch dependency to your project and create a node, as indicated in the reference :

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

After creating the node, it will behave exactly like a node launched from the command line. You can interact with it using the created client object, but by default it will also open ports 9200 and 9300 (or the following if busy) for rest calls and node interactions.

+10
source share

All Articles