使用python脚本连接到ES

使用python脚本连接到ES,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我正在尝试从ES引擎连接和检索数据 我正在使用以下脚本: from elasticsearch import Elasticsearch as ES print "Setup connection..." es=ES(['http://elasticsearch......com:9200/cuevents-2014.34,cuevents-2014.33/_search?pretty']) print "Done!" print "Count number of users..." pri

我正在尝试从ES引擎连接和检索数据

我正在使用以下脚本:

from elasticsearch import Elasticsearch as ES

print "Setup connection..."
es=ES(['http://elasticsearch......com:9200/cuevents-2014.34,cuevents-2014.33/_search?pretty'])
print "Done!"

print "Count number of users..."
print es.count(index='cuevents-2014.34')
但是我收到了下面的消息

Setup connection...
No handlers could be found for logger "elasticsearch"
Done!
Count number of users...
Traceback (most recent call last):
  File "/home/es.py", line 8, in <module>
    print es.count(index='cuevents-2014.34')
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 622, in count
    params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 284, 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 51, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', gaierror(-2, 'Name or service not known'))) caused by: ProtocolError(('Connection aborted.', gaierror(-2, 'Name or service not known')))
设置连接。。。
找不到记录器“elasticsearch”的处理程序
完成!
计算用户数。。。
回溯(最近一次呼叫最后一次):
文件“/home/es.py”,第8行,在
打印es.计数(索引='cuevents-2014.34')
文件“/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py”,第68行,以
返回函数(*args,params=params,**kwargs)
文件“/usr/local/lib/python2.7/dist packages/elasticsearch/client/_init__.py”,第622行,计数
参数=参数,主体=主体)
文件“/usr/local/lib/python2.7/dist packages/elasticsearch/transport.py”,第284行,在执行请求中
状态、标题、数据=连接。执行_请求(方法、url、参数、正文、忽略=忽略、超时=超时)
文件“/usr/local/lib/python2.7/dist packages/elasticsearch/connection/http_urllib3.py”,第51行,在执行请求中
升起连接器错误('N/A',str(e),e)
elasticsearch.exceptions.ConnectionError:ConnectionError(('Connection aborted',gaierror(-2,'名称或服务未知'))由以下原因引起:协议错误('Connection aborted',gaierror(-2,'名称或服务未知'))

我正在尝试连接并返回索引cuevents-2014中的文档数。34

好的,我再次更仔细地查看了您的代码。Elasticsearch构造函数需要指向根URL——您不应该在URL上指定索引

from elasticsearch import Elasticsearch as ES

print "Setup connection..."
es=ES(['http://elasticsearch......com:9200/'])
print "Done!"

print "Count number of users..."
print es.count(index='cuevents-2014.34')


如果您只想限制对某些索引的访问,Elasticsearch根本不提供访问控制。你可以通过在反向代理上重写URL来实现这一点。

听起来很明显,但你确定索引cuevents-2014.34存在吗?是的,我可以确定索引存在。当我使用以下内容时,我从惊奇漫画感知界面得到响应。”代码'curl-XGET'-d'{“size”:0,“聚合”:{“coeunt”:{“terms”:{“field”:“site_name”,“size”:0}}}“code”