I want to GET the data from a given URL (with a prefix) using ElasticSearch in Python. Here is my code:
if __name__ == '__main__':
username = "xxxx"
password = "xxxx"
url = "http://xxxx.xxx:80/xxxx/xxxx/"
_es = Elasticsearch([url], http_auth=(username, password))
if _es.ping():
print('Connect')
print(_es)
res = _es.search(index='index1', body={"query": {"match_all": {}}})
print(res)
else:
print('It could not connect!')
Actually, I can ping _e, and the _es will be an elastic object as:
<Elasticsearch([{'host': 'xxxx.xxx', 'url_prefix': 'xxxx/xxxx/', 'port': 80}])>
Also, to verify my URL, port and prefix, I checked it in Postman, I can get the data in a Json format correctly. But when I run the code in Python, I recieved the following error:
Connect
<Elasticsearch([{'host': 'xxxx.xxx', 'url_prefix': 'xxxx/xxxx/', 'port': 80}])>
Traceback (most recent call last):
File "/----.py", line 29, in <module>
res = _es.search(index='index1', body={"query": {"match_all": {}}})
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/utils.py", line 139, in _wrapped
return func(*args, params=params, headers=headers, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/__init__.py", line 1484, in search
body=body,
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/transport.py", line 352, in perform_request
timeout=timeout,
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/http_urllib3.py", line 256, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/base.py", line 288, in _raise_error
status_code, error_message, additional_info
elasticsearch.exceptions.NotFoundError: NotFoundError(404, '{"code":404,"message":"HTTP 404 Not Found"}')
Any Idea?