14

I've put together a simple search form, with a search box and a couple of filters as dropdowns. Everything works as you'd expect, except that I want the behavior to be that when the user leaves everything completely blank (no search query, no filters) they simply get everything returned (paginated of course).

I'm currently achieving this by detecting this special case and querying my local database, but there are some advantages to doing it 100% with CloudSearch. Is there a way to build a request that simply returns a paginated list of every document? In other words, is there a CloudSearch equivalent to "SELECT id FROM x LIMIT n?"

Thanks in advance! Joe

Joe
  • 1,723
  • 2
  • 14
  • 16

3 Answers3

39

See the Search API. ?q=matchall&q.parser=structured will match all the documents.

user2602740
  • 637
  • 6
  • 17
  • 1
    Relevant documentation http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-text.html#searching-text-prefixes – russau Mar 14 '15 at 03:27
  • With the default configuration, AWS only returns the top 10 hits of a query. I know you can edit it with the size param, but is there a way to tell AWS to remove the limit and return ALL the data as hits? I haven't seemed to find a solution... – welshk91 Mar 28 '16 at 21:28
  • 5
    _(For future google searchers)_ There's a 10,000 record limit before you have to start iterating using cursors. – Scuzzy May 15 '16 at 21:54
13

These easiest way would be to use a not operator, so for example:

?q=dog|-dog

would return all documents that contained 'dog' and also did not contain 'dog'. You would need to intercept the special case, as you are already, and just substitute a query/not query combo and you should get everything back.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
0

For someone looking for an answer using boto3.

CLOUD_SEARCH_CLIENT = boto3.client(
    'cloudsearchdomain',
    aws_access_key_id='',
    aws_secret_access_key='',
    region_name='',
    endpoint_url="https://search-your-endpoint-url.amazonaws.com"
)

response = CLOUD_SEARCH_CLIENT.search(
    query="matchall",
    queryParser='structured'
)

print(response)
Joshua Wolff
  • 2,687
  • 1
  • 25
  • 42