0

我正在嘗試使用python創建我的第一個索引,並且我一直收到404索引未找到的異常。這裏是當前的代碼:創建AWS Elasticsearch索引時出現404 HEAD問題

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是什麼意思?現在

es = Elasticsearch(
    hosts = host, 
    connection_class = RequestsHttpConnection, 
    port = 443, 
    use_ssl = True, 
    verify_certs = False) 

正常工作:

+0

這可能就是它如何測試索引是否已經存在。 – kichik

+0

我已登錄AWS並多次刷新,但仍未看到索引。 – maltman

回答

0

改變了我來連接。不知道爲什麼前一個失敗。