Skip to content

Commit 279d2ff

Browse files
committed
Wire IndicesQueryCache into analytics filter delegation path
The analytics engine's Lucene delegation creates a bare IndexSearcher without the node-level query cache. This means every filter delegation re-traverses the posting list from scratch, even for repeated text predicates across queries. Fix: LucenePlugin exposes setIndicesQueryCache(cache, policy) for node setup to wire. LuceneAnalyticsBackendPlugin.getFilterDelegationHandle() attaches the cache to the IndexSearcher it creates. TODO: wire LucenePlugin.setIndicesQueryCache() from IndicesService during node startup (requires passing IndicesQueryCache through plugin lifecycle). Effect: repeated queries on same text term (e.g., match('http') across 14 queries) will cache the BitSet after first evaluation — subsequent queries return cached result in ~0ms instead of ~300ms. Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
1 parent 4edd9fc commit 279d2ff

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

sandbox/plugins/analytics-backend-lucene/src/main/java/org/opensearch/be/lucene/LuceneAnalyticsBackendPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ public FilterDelegationHandle getFilterDelegationHandle(List<DelegatedExpression
155155
IndexReaderProvider.Reader reader = shardCtx.getReader();
156156
LuceneReader luceneReader = reader.getReader(plugin.getDataFormat(), LuceneReader.class);
157157
IndexSearcher searcher = new IndexSearcher(luceneReader.directoryReader());
158+
if (plugin.getIndicesQueryCache() != null) {
159+
searcher.setQueryCache(plugin.getIndicesQueryCache());
160+
searcher.setQueryCachingPolicy(plugin.getQueryCachingPolicy());
161+
}
158162
QueryShardContext queryShardContext = buildMinimalQueryShardContext(shardCtx, searcher);
159163
BooleanSupplier isCancelled = () -> {
160164
Task task = shardCtx.getTask();

sandbox/plugins/analytics-backend-lucene/src/main/java/org/opensearch/be/lucene/LucenePlugin.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,30 @@
5454
public class LucenePlugin extends Plugin implements DataFormatPlugin, SearchBackEndPlugin<LuceneReader>, EnginePlugin {
5555

5656
private static final LuceneDataFormat DATA_FORMAT = new LuceneDataFormat();
57+
private volatile org.apache.lucene.search.QueryCache indicesQueryCache;
58+
private volatile org.apache.lucene.search.QueryCachingPolicy queryCachingPolicy;
5759

5860
/** Creates a new LucenePlugin. */
5961
public LucenePlugin() {}
6062

63+
/**
64+
* Wire the node-level query cache for filter delegation. Called during node setup
65+
* so that the analytics engine's Lucene delegation path benefits from the same
66+
* query caching as the classic search path.
67+
*/
68+
public void setIndicesQueryCache(org.apache.lucene.search.QueryCache cache, org.apache.lucene.search.QueryCachingPolicy policy) {
69+
this.indicesQueryCache = cache;
70+
this.queryCachingPolicy = policy;
71+
}
72+
73+
public org.apache.lucene.search.QueryCache getIndicesQueryCache() {
74+
return indicesQueryCache;
75+
}
76+
77+
public org.apache.lucene.search.QueryCachingPolicy getQueryCachingPolicy() {
78+
return queryCachingPolicy;
79+
}
80+
6181
// --- DataFormatPlugin ---
6282

6383
/** {@inheritDoc} Returns the singleton {@link LuceneDataFormat} descriptor. */

0 commit comments

Comments
 (0)