matt hoover
matt hoover

Reputation: 346

Launch elasticsearch server using python code

I would like to write a script in python which creates an elasticsearch server at localhost 9200. All of the examples that I find online regard connecting to an existing elasticsearch instance running at localhost 9200. My motivation is that I don't want to have to use the command line to run or shutoff the server.

Basically replace this line

 bin/elasticsearch

with something in python.

UPDATE: I tried the following

subprocess.popen('elasticsearch-1.4.0/bin/elasticsearch')

However, I am getting the error "AttributeError: 'module' object has no attribute 'popen'"

My application.py file will run the elasticsearch service and then create another service which I can use to make calls to the elasticsearch server.

Could anyone provide a code snippet of how I would go about creating the elasticsearch instance programmatically? Are there any existing projects that do this? Thanks in advance for any help.

Upvotes: 0

Views: 1491

Answers (3)

kundan saha
kundan saha

Reputation: 1

Elasticsearch takes some time to start. That's why you may not be able to see the connection and run the following commands immediately. Try running the script again after a few seconds.

Upvotes: 0

matt hoover
matt hoover

Reputation: 346

from os import popen
import subprocess

subprocess.Popen('elasticsearch-1.4.0/bin/elasticsearch')

Upvotes: 3

tzzz
tzzz

Reputation: 1

something like this?

from os import popen
popen('bin/elasticsearch')

Upvotes: 0

Related Questions