I have a program that indexes multiple documents into OpenSearch every second. I make these documents available to query on a dashboard with a fixed set of filters. From what I've read online, OpenSearch will cache the results of queries.
When I index a new document or update an existing document, do I need to explicitly clear the index cache for the new (or updated) document to be available immediately after the index's refresh period elapses, or is the cache smart enough to know that the index has been updated?
My goal here is to prevent outdated data from being returned upon explicit requests, but I'd still like to cache it in the case that multiple users attempt to query the documents when no change has occurred.
You don't need to worry about query cache, node cache and request cache. Those are low-level caches that will never return you stale information.
The main parameter to take into account to have fresh results is the refresh_interval
. The shorter it is the more real-time your results are, but also the more load your put on your index. But usually 1s
is perfectly admissible for near-real time cases like yours.