AWS CloudSearch: how to search a large subset?

2019-07-31 19:45发布

问题:

I simply want to search a large subset of ids within our CloudSearch index.

I have tried with a structured query (and also with a simple query plus a filterQuery), for example this narrows the search to three records only, those with item_key of 36933, 36940, or 36950.

(or (term field=item_key 'item_36933') (term field=item_key 'item_36940') (term field=item_key 'item_36950'))

This works, and it is obviously easy to expand that structured query to include many items. However, there seems to be a limit of 50 such terms in CloudSearch :-( which is a problem as I need to search sets of many more than 50 items, but still only a fraction of the overall index.

How can I do this, for an arbitrary set of say 1000 items, without resorting to searching the entire index and then filtering the results?

回答1:

CloudSearch supports 1024 clauses per search.

This means you can do a search against a field matching up to 1024 values, like

field_name: "value1" OR "value2" OR ... OR "value1024"

If your service needs to support more than 1024 individual matches, then you will need to split into multiple queries of 1024 and combine the results.