Hello,
I have written below code to accept input from keyboard and retrieve data from elasticsearch cluster
from elasticsearch import Elasticsearch
from datetime import datetime
es = Elasticsearch (“https://localhost”, api_key=“ACKRUSGHUSGHEHYFIRHU==”)
Index_pattern = “test-*”
service_name = input("Enter service name: ")
query = {
“query”: {
“bool”: {
“must”: [
{
“range”: {
“@timestamp”: {
“gte”: “now-1h”
}
}
},
{
“term”: {
“service.name”: ‘service_name’ #here using above declared variable
}
}
]
}
}
}
result = es.search(index=index_pattern, body=query)
for hit in result[‘hits’][hits’]:
Print(hit['_source])
When I execute the code asking for input but not retrieving data from. Elastic server. What is the mistake here ?