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.

matt hoover
  • 326
  • 2
  • 7
  • 23

3 Answers3

2
from os import popen
import subprocess

subprocess.Popen('elasticsearch-1.4.0/bin/elasticsearch')
matt hoover
  • 326
  • 2
  • 7
  • 23
0

something like this?

from os import popen
popen('bin/elasticsearch')
tzzz
  • 1
  • 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? – matt hoover Nov 09 '14 at 23:47
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.