【发布时间】:2019-11-04 08:47:10
【问题描述】:
我想在启动时自动检查并创建(如果不存在)我的应用程序的弹性搜索索引,这是我目前无法正常工作的情况:
echo "Checking if Elasticsearch index is setup"
{
cat <<EOF | python /manage.py shell
from elasticsearch import Elasticsearch
HOST_URLS = ["elasticsearch:9200"]
es_conn = Elasticsearch(HOST_URLS)
INDEX_NAME = "posts"
res = es_conn.indices.exists(index=INDEX_NAME)
if res == True:
print("Elasicsearch index seems already setup, skipping")
else:
print("Elasicsearch index not setup yet, creating ...")
import subprocess
subprocess.Popen("y | python manage.py search_index --rebuild", shell=True, stdout=subprocess.PIPE).communicate()[
0].decode('utf-8').strip()
EOF
}>/dev/null
这再次导致:
"'{}' 索引?[n/Y]: ".format(", ".join(index_names)))
| EOFError:读取一行时出现EOF
python manage.py search_index --rebuild 来自:https://github.com/sabricot/django-elasticsearch-dsl/
【问题讨论】:
标签: python django elasticsearch automation startup