我正在尝试使用python创建我的第一个索引,并且我不断获得404索引未找到异常。这是当前的代码:
es = Elasticsearch([{'host': 'host_url', 'port': 443, 'use_ssl': True, 'timeout': 300}])
if es.indices.exists('test_logs'):
es.indices.delete(index = 'test_logs')
request_body = {
'settings': {
'number_of_shards': 2,
'number_of_relicas': 2
},
'mappings': {
'logs': {
'properties': {
'date': { 'index': 'not_analyzed', 'type': 'date' },
'time': { 'index': 'not_analyzed', 'type': 'time' },
'request': { 'index': 'not_analyzed', 'type': 'string' },
'status': { 'index': 'not_analyzed', 'type': 'int' },
'agent': { 'index': 'not_analyzed', 'type': 'string' }
}
}
}
}
es.indices.create(index = 'test_logs', ignore = [400, 404], body = request_body, request_timeout = 30)
编辑:我已经改变了一些东西,现在我得到了一个不同的错误。我更新了新问题的代码和标题。这是我的输出:
C:\Python34\lib\site-packages\elasticsearch\connection\http_urllib3.py:54: UserW
arning: Connecting to host_url using SSL with verify_certs=False is insecure.
'Connecting to %s using SSL with verify_certs=False is insecure.' % host)
C:\Python34\lib\site-packages\urllib3\connectionpool.py:789: InsecureRequestWarn
ing: Unverified HTTPS request is being made. Adding certificate verification is
strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
HEAD /test_logs [status:404 request:0.902s]
C:\Python34\lib\site-packages\urllib3\connectionpool.py:789: InsecureRequestWarn
ing: Unverified HTTPS request is being made. Adding certificate verification is
strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
Press any key to continue . . .
HEAD / test_logs 404是什么意思?
答案 0 :(得分:1)
将我的连接更改为:
es = Elasticsearch(
hosts = host,
connection_class = RequestsHttpConnection,
port = 443,
use_ssl = True,
verify_certs = False)
现在工作正常。不知道为什么前一个失败了。