简体   繁体   中英

Cloudsearch and API Gateway structured query phrase search

I am integrating Amazon Cloudsearch with API Gateway. Everything is working fine except when I try to do a structured query phrase search.

I use this syntax in the Cloudsearch Test Search: (phrase field=title 'search') and it works great. I look at their JSON and they send it like this:

CloudSearchAPI/search?q=(phrase+field%3Dcontent+'search')&q.parser=structured

My API integrates with the Cloudsearch http endpoint to match that format but when I try to perform the exact same query I get the following error

APIURL/(phrase+field%3Dcontent+'search')&q.parser%3Dstructured

[ Deprecated : Use the outer message field]

It's as if the "=" sign gets decode before it's sent to the cloudsearch endpoint. Does anyone have any idea on how to overcome this?

Also, I am using javascript to send the AJAX request. Here is how I am encoding the phrase search:

encodeURIComponent("(phrase field=content '" + term + "')") //turns in to: phrase%20field%3Dcontent%20'search'

It works if I don't include the field=content part

Thanks!

If you're using a library to perform the AJAX request (eg Axios, jQuery), you probably don't need to URI encode that string before sending the request. I'm using the following filter query in my app (which is a very similar syntax to your query) and it works just fine without encodeURIComponent :

fq: '(term field=search_type_lit \\'Suggestion\\')'

If you encode that string before using an AJAX library (which will probably provide encoding for you) it will get double-encoded and CloudSearch won't recognize it as valid query syntax.

Just to illustrate, here's what's probably happening to the equals sign alone, if it gets encoded once by encodeURIComponent and then again by your AJAX library.

  • Unencoded: =
  • Encoded once: %3D
  • Encoded twice: %253D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM