Python : Wildcard Query In Elasticsearch
I want to query a field using wildcard in Elasticsearch but the problem is that the search string is stored in a variable and not available statically. The intended query is : body
Solution 1:
You have to use +
concatenation in python
.
And you need to escape double quotes. There are many ways to do this. I prefer escaping double quotes as \"
searchWord ="Vi";
query ="{\"query\": {\"wildcard\": {\"Name\": { \"value\" : \""+ searchWord +"?????\" }}}}";
print (query);
searchWord
is something that you receive from the user. I hardcoded it.
query
is the one you need to form. This is how I formed it \"" + searchWord + "?????\"
Please check and provide any information which I need to consider.
EDIT:
searchWord ="Vi";
x =2;
query ="{\"query\": {\"wildcard\": {\"Name\": { \"value\" : \""+"[a-z]{"+ str(x) +"}"+ searchWord +"?????\" }}}}";
print (query);
Post a Comment for "Python : Wildcard Query In Elasticsearch"