How to provide input from keyboard to script. Input can be service name or application

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 ?

Please try to help here

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the Community Code of Conduct specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a subscription.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

2 Likes

Hello! In addition to what David mentioned, here are other tips to make sure we can help you effectively:

I was about to give specific advice around quotes, but I just noticed that @jessgarson replied to Test Rest API through python - #14 by jessgarson with much more details than I would have. Please don't post duplicate questions like this. And let's focus on the other thread now.

2 Likes