0

I have a piece of python query to retrieve data from elasticsearch:-

es=Elasticsearch(['http://localhost:9200'])
res = es.search(index="index1", doc_type="log",size=1000, from_=0, body={              "query": {
  "match": {
  ....Match condition
  }
 }
}})

Is there any way we can pass the index as parameter i.e assign the value of index1 outside the query and then use it for extracting results?

anas p a
  • 383
  • 5
  • 20
Mayank Jha
  • 939
  • 3
  • 12
  • 24

1 Answers1

3

I believe you do not want to hard code the index value. IF that is the case you can always use format

'{0}'.format(*args, **kwargs)

In your case you can write like this:

res = es.search(index='{0}'.format(index1), doc_type="log",size=1000, from_=0, body={ "query": { "match": { ....Match condition } } }})
eshwar m
  • 184
  • 4