Class ReaderContext
java.lang.Object
org.elasticsearch.search.internal.ReaderContext
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.elasticsearch.core.Releasable
- Direct Known Subclasses:
LegacyReaderContext
Holds a reference to a point in time
Engine.Searcher
that will be used to construct SearchContext
.
This class also implements RefCounted
since in some situations like
in SearchService
a SearchContext can be closed concurrently due to independent events
ie. when an index gets removed. To prevent accessing closed IndexReader / IndexSearcher instances the SearchContext
can be guarded by a reference count and fail if it's been closed by an external event.-
Field Summary
-
Constructor Summary
ConstructorDescriptionReaderContext(ShardSearchContextId id, IndexService indexService, IndexShard indexShard, Engine.SearcherSupplier searcherSupplier, long keepAliveInMillis, boolean singleSession)
-
Method Summary
Modifier and TypeMethodDescriptionacquireSearcher(String source)
void
addOnClose(org.elasticsearch.core.Releasable releasable)
void
close()
getAggregatedDfs(AggregatedDfs other)
<T> T
getFromContext(String key)
Returns the object ornull
if the given key does not have a value in the contextgetRescoreDocIds(RescoreDocIds other)
long
id()
boolean
org.elasticsearch.core.Releasable
markAsUsed(long keepAliveInMillis)
Returns a releasable to indicate that the caller has stopped using this reader.void
putInContext(String key, Object value)
Puts the object into the contextvoid
setAggregatedDfs(AggregatedDfs aggregatedDfs)
void
setRescoreDocIds(RescoreDocIds rescoreDocIds)
boolean
Returnstrue
for readers that are intended to use in a single query.void
validate(TransportRequest request)
-
Field Details
-
searcherSupplier
-
-
Constructor Details
-
ReaderContext
public ReaderContext(ShardSearchContextId id, IndexService indexService, IndexShard indexShard, Engine.SearcherSupplier searcherSupplier, long keepAliveInMillis, boolean singleSession)
-
-
Method Details
-
validate
-
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.elasticsearch.core.Releasable
-
addOnClose
public void addOnClose(org.elasticsearch.core.Releasable releasable) -
id
-
indexService
-
indexShard
-
acquireSearcher
-
markAsUsed
public org.elasticsearch.core.Releasable markAsUsed(long keepAliveInMillis)Returns a releasable to indicate that the caller has stopped using this reader. The time to live of the reader after usage can be extended using the providedkeepAliveInMillis
. -
isExpired
public boolean isExpired() -
getShardSearchRequest
-
scrollContext
-
getAggregatedDfs
-
setAggregatedDfs
-
getRescoreDocIds
-
setRescoreDocIds
-
singleSession
public boolean singleSession()Returnstrue
for readers that are intended to use in a single query. For readers that are intended to use in multiple queries (i.e., scroll or readers), we should not release them after the fetch phase or the query phase with empty results. -
getFromContext
Returns the object ornull
if the given key does not have a value in the context -
putInContext
Puts the object into the context -
getStartTimeInNano
public long getStartTimeInNano()
-