Amazon CloudSearch: Is it possible to write a query that returns... everything?
Asked Answered
D

3

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

Denominational answered 30/12, 2013 at 22:52 Comment(0)
T
41

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

Titus answered 21/5, 2014 at 3:38 Comment(3)
Relevant documentation docs.aws.amazon.com/cloudsearch/latest/developerguide/…Vallee
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...Thursday
(For future google searchers) There's a 10,000 record limit before you have to start iterating using cursors.Gabrielegabriell
K
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.

Karns answered 31/12, 2013 at 14:5 Comment(2)
At first I had to laugh about this answer. But the good thing is: it works on the Test-Search-Console of the AWS-Interface (where matchall does not).Arcturus
Cleaver reasoning, I must sayEthanethane
A
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)
Absquatulate answered 17/3, 2020 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.