0

我想用python编写一个脚本,在localhost 9200创建一个elasticsearch服务器。我在网上找到的所有示例都连接到在localhost 9200运行的现有elasticsearch实例。我的动机是我不想必须使用命令行运行或关闭服务器。

基本上替换这一行

 bin/elasticsearch

用python中的东西。

更新:我尝试了以下

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

但是,我收到错误“AttributeError:'module'对象没有属性'popen'”

我的 application.py 文件将运行 elasticsearch 服务,然后创建另一个服务,我可以使用它来调用 elasticsearch 服务器。

谁能提供我将如何以编程方式创建弹性搜索实例的代码片段?是否有任何现有的项目可以做到这一点?提前感谢您的帮助。

4

3 回答 3

2
from os import popen
import subprocess

subprocess.Popen('elasticsearch-1.4.0/bin/elasticsearch')
于 2014-11-15T04:17:25.973 回答
0

像这样的东西?

from os import popen
popen('bin/elasticsearch')
于 2014-11-09T21:02:44.623 回答
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.

于 2021-02-02T09:24:12.283 回答