Skip to content

Instantly share code, notes, and snippets.

@masudur-rahman-niloy
Created August 19, 2022 03:15
Show Gist options
  • Save masudur-rahman-niloy/b1570cca2930cb1029c5c7ffcab966b4 to your computer and use it in GitHub Desktop.
Save masudur-rahman-niloy/b1570cca2930cb1029c5c7ffcab966b4 to your computer and use it in GitHub Desktop.
from elasticsearch import Elasticsearch
import sys
ELASTIC_PASSWORD = sys.argv[1]
client = Elasticsearch(
"https://localhost:9200",
ca_certs="/etc/elasticsearch/certs/http_ca.crt",
basic_auth=("elastic", ELASTIC_PASSWORD)
)
client.indices.refresh(index="test-index")
resp = client.search(index="test-index", query={"match_all": {}})
print("Got %d Hits:" % resp['hits']['total']['value'])
for hit in resp['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment