How to access Records from Elasticsearch using python dynamically

Dear all.
i have below in python but that one static value passed.

but need access the same code from services in dynamic way.

Import Elasticsearch package

from elasticsearch import Elasticsearch

Connect to the elastic cluster

es=Elasticsearch([{'host':'localhost','port':9200}]) #
print("connection has been done here")

print("you read data is:",res)


I am sure what exactly you're after but this link might help you (it did for me in past)

Hi @pjanzen
Thanks but in this page ,they are proving value in static manner.means not in dynamic way:-
For Example:-
print res['hits']['hits']
HERE:- provided first_name':'nitin' this is static way...but want to access any name: matching with Elasticsearch.

name:any name?

I use python elasticsearch in 2 use cases.

  1. I have a query which I execute and I do something with result.
  • if I have more the 1000 records I need to use the scroll function to collect all information.
  1. I have a prepared query (like what you have) and I update the the field with the data I am searching for. In your example that would be first_name. Once the query is updated you can execute it and retrieve the result.

So you need to think about your use case and if at possible share that here. If you already have developed any code please share that as well, I might be useful to help your case.


Hi @pjanzen.

we can use JDBC connection for access based on condition same as sql query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.