Amazon CloudSearch request

I get lost on how to query my Amazon CloudSearch from a static HTML page. Although the documentation is good, there are no examples besides copying and pasting the URL in the browser.

What I need is an S3 HTML page, so the server side code is not allowed to have a text box that, when the search button is clicked, launches at my CloudSearch endpoint and returns the results

CloudSearch responds using JSON, so you have to analyze this and compile a table of results.

So far I have been working with saved JSON of results locally and using Jquery I read JSON file

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Sample</title> </head> <body> <div id="placeholder"></div> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> $.getJSON('search.json', function(data) { var output="<ul>"; for (var i in data.hit) { output+="<li>" + data.hit[i].id+ "</li>"; } output+="</ul>"; document.getElementById("placeholder").innerHTML=output; console.log(data); }); </script> </body> </html> 

This gives me the post id.

But when I try to change the URL at the CloudSearch endpoint, I do not return data. After reading and going around in circles, I believe that this is because of CORS.

However, the Amazon documentation just says use HTTP GET on the endpoint, but how can I create it on my HTML page.

Sorry for such a basic question

+4
source share
5 answers

This will help you. You need to create an xml configuration file like this.

http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

0
source

CloudSearch does not currently support CORS, so your browser will not allow you to contact CloudSearch.

If you do not want to start the server, you will need to find a proxy for your requests. You can take a look at this:

Is there a free JSON proxy server that supports CORS or JSONP?

0
source

You can create an html form with all parts to search; just make sure it finishes creating the correct url, for example:

http://search-YOURDOMAIN-RANDOMID.REGION.cloudsearch.amazonaws.com/2013-01-01/search?q=THESEARCHPHRASE&q.parser=simple&start=0&size=30&return=COMMA%2cSEPARATED%2cLIST_OF_FIELDS

which would fit a form like:

 <form action="http://search-YOURDOMAIN-RANDOMID.YOURREGION.cloudsearch.amazonaws.com/2013-01-01/search" method="get"> <label>Search: <input name="q" /></label> <input type="hidden" name="q.parser" value="simple" /> <label>How many results? <select name="size"> <option>10</option> <option>20</option> </select></label> // other dropdowns, hidden inputs etc corresponding to `start`, `return`, etc <button type="submit">Search</button> </form> 

If you need help figuring out what you should send, check your network traffic (Chrome tab> F12> Network) when you are in the CloudSearch dashboard "Run a test search" ( https://console.aws.amazon.com/ cloudsearch / home? region = YOURREGION # search, YOURDOMAIN ). Or read more for sample search URLs at http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching.html

0
source

Created an angularjs project that demonstrates this and is added to the git hub. You need CORS - anywhere to properly route to the domain.

https://github.com/tkntobfrk/amazon-cloudsearch-angular

In project

hints are used to search for domain data and fill in the input field with autocomplete data. Uses bootstrap.ui typeahead.

0
source

To enable the CORS API for cloud search, you can use the AWS API Gateway HTTP proxy to complete the endpoint of your cloud.

AWS API Gateway allows you to enable CORS.

For my configuration, I added Passthrough for these fields, defining the endpoint: start, sort, q.options, q.parser, return, fq, q, size

You can map each of these options as follows:

 method.request.querystring.start method.request.querystring.sort method.request.querystring.q.options etc. 
0
source

All Articles