I have a Tasks index with following fields:
- user_id (integer)
- category_id (integer)
- location (lat, lon)
- name (string)
In the app, users can see the 100 nearest tasks on the map and assign tasks to themselves (claim). They see both unclaimed tasks, and tasks they've claimed to themselves. Easy so far. The complicated part is: if I have claimed 3 or more tasks in one category, I should no longer see any unclaimed tasks in that category, only my own.
Currently, the process is to:
- fetch 100 nearest (geospatially) tasks from OpenSearch server, where
user_idis eithernullor123 - loop through the result to count number of claimed tasks in each category
- then loop again to discard all unclaimed tasks whose category counter reached 3
- and if the resulting set is less than 100 tasks, fetch 100 more and repeat the process
This, of course, is highly ineffective. Is it possible to achieve this behaviour with OpenSearch?..
Important note: using RDBMS is not an option, it has to be done in OpenSearch.