I've been trying to construct a boolean search query, but the value of the field I'm searching on starts with a hypen -
, which normally is used as the boolean not
operator. An example might be helpful:
Suppose I had a bunch of movie records and I wanted to search for all movies with the title "-gladiator" in the "drama" genre. Normally my query would look like this:
search?bq=(and title:'-gladiator' genre:'drama')
The problem is that -
is interpreted as the not
operator so this will return to me all of the movies in the drama genre who do not have the title gladiator. I've tried escaping the hyphen with a blackslash and with a url-encoded backslash (%5C), but I get errors from CloudSearch when I do this. So far I can't find any documentation that talks about this.
Does anyone know how to escape boolean operators in boolean search queries?
Relevant documentation http://docs.aws.amazon.com/cloudsearch/latest/developerguide/booleanoperators.html http://docs.aws.amazon.com/cloudsearch/latest/developerguide/booleansearch.html
It turns out that you have to escape the operator with two backslashes. Something like this would work:
search?bq=(and title:'\\-gladiator' genre:'drama')
Also don't forget to url-encode your query string if you're attempting to test this out with curl or something similar.