I am querying elasticsearch in python. I want to change a parameter 'default operator' in case query returns zero values. Here's my code:
default_operator = "and" if searchfields is not None: if query is not None and query != '': queries.append(Q("simple_query_string", query=query, default_operator= default_operator, flags="PREFIX|PHRASE|NOT|AND|OR|FUZZY|WHITESPACE", fields=searchfields))
There is a long code after this in which different filters are being made and added to the query. But here's the code where I am trying to change the default operator:
res = s.execute() if res["hits"]["total"]["value"] == 0: default_operator = "or" print("Query with default operator OR: ", str(queries)) res = s.execute() else: pass
But it is not changing the default operator. How can I do this?