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}]) #http://127.0.0.1:9200
print("connection has been done here")
res=es.get(index='megacorp',doc_type='employee',id='4')

print("you read data is:",res)
print("-----------------------------------------------------------")
print(res['_source'])

Hi,

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:-
res= es.search(index='megacorp',body={
'query':{
'bool':{
'must':{
'match':{
'first_name':'nitin'
}
},
"filter":{
"range":{
"age":{
"gt":25
}
}
}
}
}
})
print res['hits']['hits']
HERE:- provided first_name':'nitin' this is static way...but want to access any name: matching with Elasticsearch.

like:-
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.

Paul.

Hi @pjanzen.

we can use JDBC connection for that.to 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.