maltman maltman - 2 months ago 15
Python Question

404 HEAD issue when creating AWS Elasticsearch index

I am trying to create my first index using python and I keep getting a 404 index not found exception. Here is the current code:

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)


EDIT: I have changed some things and now I get a different error. I have updated my code and title for the new issue. Here is my output:

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 . . .


What does the HEAD /test_logs 404 mean?

Answer

Changed my connection to:

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

Works fine now. Do not know why the previous one failed.