-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
ConcurrentSearchRequestDecider.java
58 lines (50 loc) · 2.48 KB
/
ConcurrentSearchRequestDecider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.search.deciders;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.query.QueryBuilder;
import java.util.Optional;
/**
* {@link ConcurrentSearchRequestDecider} allows pluggable way to evaluate if a query in the search request
* can use concurrent segment search using the passed in queryBuilders from query tree and index settings
* on a per shard request basis.
* Implementations will need to implement the Factory interface that can be used to create the ConcurrentSearchRequestDecider
* This factory will be called on each shard search request to create the ConcurrentSearchRequestDecider and get the
* concurrent search decision from the created decider on a per-request basis.
* For all the deciders the evaluateForQuery method will be called for each node in the query tree.
* After traversing of the query tree is completed, the final decision from the deciders will be
* obtained using {@link ConcurrentSearchRequestDecider#getConcurrentSearchDecision}
*/
@ExperimentalApi
public abstract class ConcurrentSearchRequestDecider {
/**
* Evaluate for the passed in queryBuilder node in the query tree of the search request
* if concurrent segment search can be used.
* This method will be called for each of the query builder node in the query tree of the request.
*/
public abstract void evaluateForQuery(QueryBuilder queryBuilder, IndexSettings indexSettings);
/**
* Provide the final decision for concurrent search based on all evaluations
* Plugins may need to maintain internal state of evaluations to provide a final decision
* If decision is null, then it is ignored
* @return ConcurrentSearchDecision
*/
public abstract ConcurrentSearchDecision getConcurrentSearchDecision();
/**
* Factory interface that can be implemented to create the ConcurrentSearchRequestDecider object.
* Implementations can use the passed in indexSettings to decide whether to create the decider object or
* return {@link Optional#empty()}.
*/
@ExperimentalApi
public interface Factory {
default Optional<ConcurrentSearchRequestDecider> create(IndexSettings indexSettings) {
return Optional.empty();
}
}
}