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?

1 Answer 1

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 } } }})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, that's what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.