0

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.

1
  • 1
    with a capital P : subprocess.Popen(...) Commented Nov 10, 2014 at 12:08

3 Answers 3

3
from os import popen
import subprocess

subprocess.Popen('elasticsearch-1.4.0/bin/elasticsearch')
Sign up to request clarification or add additional context in comments.

Comments

0

something like this?

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

1 Comment

popen allows me to run elasticsearch, but then the lines of code after popen don't get executed. I think that the program is hanging on popen. Should I spawn a separate thread?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.