2

I'm trying to access Kibana console from my python script since proxy don't allow me to access Elasticsearch in local but Kibana I can.

My intention is to run Elasticsearch queries with accessing Kibana locally to debug before deploying my application to server.

Here is what I have tried:

url = "myhost/myindex/_search"
query = '{"match":{"col1":"value"}}'
requests.get(url, verify="path", auth=(user, pwd), body=query)

This is returning http 200 but the content is showing a html page and I can't find my actual query response anywhere. Could some one help to find a way to get the query results.

Note: Elastic version is 7.3

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
RAVITEJA SATYAVADA
  • 2,503
  • 23
  • 56
  • 88

3 Answers3

2

According to Kibana's documentation, the simplest way is to use query parameters such as q=col1:value. If you want to use request body parameters, the proper structure is:

GET /my-index/_search
        {
          "query": {
            "term": {
              "col1": "value"
            }
          }
        } 
farzado
  • 71
  • 3
  • Wildcards for indices also work: `GET /my-index-*` will do the search in all matching indices – VMAtm Aug 23 '23 at 12:54
0

try following query

"query_string": {"query":"value","default_field":"col1"}

also you can try postman

Omk
  • 1
  • 2
  • 16
0
from json import loads
from requests import post 
    
result = post(auth=(user, password), data=query, headers=HEADERS, url=URL)
result_json = loads(result.text)

You should already know what user, password, and query are. To find HEADERS and URL we will build on the solutions here and here.

Use the Chrome Dev Tools to grab the URL; it will start with https and end with proxy?path=_search&method=POST or some such. Then in Chrome Dev Tools look at the request headers for your successful Kibana Dev Tools Console query. You want the one labeled Cookie. Then

HEADERS = {
     'Content-Type': 'application/json',
     'kbn-xsrf': 'true',
     'Cookie': your cookie goes here
}

And you should be good to go.

HenryDrain
  • 13
  • 4