pythonelasticsearchpyelasticsearch

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.


Solution

  • from os import popen
    import subprocess
    
    subprocess.Popen('elasticsearch-1.4.0/bin/elasticsearch')