我有一个使用 Elastic Search 的应用程序。我有一个 Python 客户端问题,它不能与 Elastic Search 通信。我已经为 python 安装了 Elasticsearch 客户端。这是我的python代码:
from elasticsearch import Elasticsearch
doc = {
'name': 'example.txt',
'text': 'Elasticsearch: cool',
}
es = Elasticsearch("localhost:9200")
print(es.cat.health())
我使用 Elasticsearch 泊坞窗图像。我的 docker compose 设置在这里:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
container_name: elasticsearch
ports:
- 9200:9200
- 9300:9300
environment:
ES_JAVA_OPTS: '-Xms256m -Xmx256m'
network.bind_host: 0.0.0.0
network.host: 0.0.0.0
discovery.type: single-node
我检查链接 http://localhost:9200 以查看 elastichsearch docker setup 是否有效,并且 url 会返回给我,这意味着有效。
{
"name" : "d39e7c4de305",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "OYqvdY8TSHeLQoVqXLH5fg",
"version" : {
"number" : "7.12.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a",
"build_date" : "2021-03-18T06:17:15.410153305Z",
"build_snapshot" : false,
"lucene_version" : "8.8.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
但是elasticksearch和python客户端之间没有通信。任何人都知道我该如何解决它?提前致谢。