我有两个使用docker bridge网络的docker容器。
一个容器运行Elasticsearch 2.6.1。另一个有一个运行了一些python代码的ubuntu映像。
无论我想执行什么弹性搜索查询,它都可以使用来自ubuntu容器shell的Curl完美地工作。
当我尝试使用Python-Elasticsearch库在ubuntu容器中执行相同操作时,我收到一个超时错误:
Traceback (most recent call last):
File "test_elastics.py", line 11, in <module>
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 279, in index
_make_path(index, doc_type, id), params=params, body=body)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 329, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 102, in perform_request
raise ConnectionTimeout('TIMEOUT', str(e), e)
elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host=u'172.17.0.1', port=9200): Read timed out. (read timeout=30))
我在RHEL发行版上使用docker 1.7.1。
运行最新Docker CE 17.06的macbook上的相同容器运行完美。
我不明白发生了什么,如果Curl能够达到elasticsearch为什么不是urllib?
感谢您的帮助。
PS:奇怪的是,似乎python脚本能够创建索引......更新1
我用于elasticsearch容器的docker镜像是https://github.com/partlab/docker/tree/master/ubuntu-elasticsearch
我将这两行添加到elasticsearch.yml:
script.inline: true
script.indexed: true
我使用以下命令行运行容器:
sudo docker run -d -p 9200:9200 -p 9300:9300 --name cca_elasticsearch -v /home/myhome/elastic_data dc6da47c125a
更新2
curl要求我尝试:
foo@b8b74b6e5609:~$ curl 172.17.0.1:9200
{
"name" : "Puff Adder",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "s58rhxIuRKqUjEJF-ckOIQ",
"version" : {
"number" : "2.4.6",
"build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
"build_timestamp" : "2017-07-18T12:17:44Z",
"build_snapshot" : false,
"lucene_version" : "5.5.4"
},
"tagline" : "You Know, for Search"
}
检查索引的另一个:
foo@b8b74b6e5609:~$ curl '172.17.0.1:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size
我尝试了这个新的失败,抱歉我在测试中并不彻底:
foo@b8b74b6e5609:~$ curl -XPUT '172.17.0.1:9200/megacorp/employee/1?pretty' -H 'Content-Type: application/json' -d' { "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] } '
{
"error" : {
"root_cause" : [ {
"type" : "unavailable_shards_exception",
"reason" : "[megacorp][3] primary shard is not active Timeout: [1m], request: [index {[megacorp][employee][1], source[ { \"fir
st_name\" : \"John\", \"last_name\" : \"Smith\", \"age\" : 25, \"about\" : \"I love to go rock climbing\", \"interests\": [ \"sports
\", \"music\" ] } ]}]"
} ],
"type" : "unavailable_shards_exception",
"reason" : "[megacorp][3] primary shard is not active Timeout: [1m], request: [index {[megacorp][employee][1], source[ { \"first
_name\" : \"John\", \"last_name\" : \"Smith\", \"age\" : 25, \"about\" : \"I love to go rock climbing\", \"interests\": [ \"sports\"
, \"music\" ] } ]}]"
},
"status" : 503
}
这似乎与我的Python代码相同:
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch('172.17.0.1:9200')
doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['created'])
更新3
我的弹性搜索停止程序发生了一些错误,我只是注意到了它。
以下是该容器的docker日志的尾部: