Class ElasticsearchDirectoryReader

java.lang.Object
org.apache.lucene.index.IndexReader
org.apache.lucene.index.CompositeReader
org.apache.lucene.index.BaseCompositeReader<org.apache.lucene.index.LeafReader>
org.apache.lucene.index.DirectoryReader
org.apache.lucene.index.FilterDirectoryReader
org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader
All Implemented Interfaces:
Closeable, AutoCloseable

public final class ElasticsearchDirectoryReader extends org.apache.lucene.index.FilterDirectoryReader
A FilterDirectoryReader that exposes Elasticsearch internal per shard / index information like the shard ID.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader

    org.apache.lucene.index.IndexReader.CacheHelper, org.apache.lucene.index.IndexReader.CacheKey, org.apache.lucene.index.IndexReader.ClosedListener
  • Field Summary

    Fields inherited from class org.apache.lucene.index.FilterDirectoryReader

    in

    Fields inherited from class org.apache.lucene.index.DirectoryReader

    directory

    Fields inherited from class org.apache.lucene.index.BaseCompositeReader

    subReadersSorter
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addReaderCloseListener(org.apache.lucene.index.DirectoryReader reader, org.apache.lucene.index.IndexReader.ClosedListener listener)
    Adds the given listener to the provided directory reader.
    protected org.apache.lucene.index.DirectoryReader
    doWrapDirectoryReader(org.apache.lucene.index.DirectoryReader in)
     
    getElasticsearchDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
    Tries to unwrap the given reader until the first ElasticsearchDirectoryReader instance is found or null if no instance is found.
    getESReaderCacheHelper(org.apache.lucene.index.DirectoryReader reader)
    Retrieves Elasticsearch's version of the reader cache helper (see ESCacheHelper)
    org.apache.lucene.index.IndexReader.CacheHelper
     
    Returns the shard id this index belongs to.
    wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId)
    Wraps the given reader in a ElasticsearchDirectoryReader as well as all it's sub-readers in ElasticsearchLeafReader to expose the given shard Id.
    wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId, ESCacheHelper esCacheHelper)
    Wraps the given reader in a ElasticsearchDirectoryReader as well as all it's sub-readers in ElasticsearchLeafReader to expose the given shard Id.

    Methods inherited from class org.apache.lucene.index.FilterDirectoryReader

    doClose, doOpenIfChanged, doOpenIfChanged, doOpenIfChanged, getDelegate, getIndexCommit, getVersion, isCurrent, unwrap

    Methods inherited from class org.apache.lucene.index.DirectoryReader

    directory, indexExists, listCommits, open, open, open, open, open, open, openIfChanged, openIfChanged, openIfChanged, openIfChanged

    Methods inherited from class org.apache.lucene.index.BaseCompositeReader

    docFreq, document, getDocCount, getSequentialSubReaders, getSumDocFreq, getSumTotalTermFreq, getTermVectors, maxDoc, numDocs, readerBase, readerIndex, totalTermFreq

    Methods inherited from class org.apache.lucene.index.CompositeReader

    getContext, toString

    Methods inherited from class org.apache.lucene.index.IndexReader

    close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, numDeletedDocs, registerParentReader, tryIncRef

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • shardId

      public ShardId shardId()
      Returns the shard id this index belongs to.
    • getReaderCacheHelper

      public org.apache.lucene.index.IndexReader.CacheHelper getReaderCacheHelper()
      Specified by:
      getReaderCacheHelper in class org.apache.lucene.index.IndexReader
    • doWrapDirectoryReader

      protected org.apache.lucene.index.DirectoryReader doWrapDirectoryReader(org.apache.lucene.index.DirectoryReader in) throws IOException
      Specified by:
      doWrapDirectoryReader in class org.apache.lucene.index.FilterDirectoryReader
      Throws:
      IOException
    • wrap

      public static ElasticsearchDirectoryReader wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId) throws IOException
      Wraps the given reader in a ElasticsearchDirectoryReader as well as all it's sub-readers in ElasticsearchLeafReader to expose the given shard Id.
      Parameters:
      reader - the reader to wrap
      shardId - the shard ID to expose via the elasticsearch internal reader wrappers.
      Throws:
      IOException
    • wrap

      public static ElasticsearchDirectoryReader wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId, @Nullable ESCacheHelper esCacheHelper) throws IOException
      Wraps the given reader in a ElasticsearchDirectoryReader as well as all it's sub-readers in ElasticsearchLeafReader to expose the given shard Id.
      Parameters:
      reader - the reader to wrap
      shardId - the shard ID to expose via the elasticsearch internal reader wrappers.
      esCacheHelper - the custom ESCacheHelper implementation that doesn't tie its lifecycle to that of the underlying reader
      Throws:
      IOException
    • getESReaderCacheHelper

      public static ESCacheHelper getESReaderCacheHelper(org.apache.lucene.index.DirectoryReader reader)
      Retrieves Elasticsearch's version of the reader cache helper (see ESCacheHelper)
    • addReaderCloseListener

      public static void addReaderCloseListener(org.apache.lucene.index.DirectoryReader reader, org.apache.lucene.index.IndexReader.ClosedListener listener)
      Adds the given listener to the provided directory reader. The reader must contain an ElasticsearchDirectoryReader in it's hierarchy otherwise we can't safely install the listener.
      Throws:
      IllegalArgumentException - if the reader doesn't contain an ElasticsearchDirectoryReader in it's hierarchy
    • getElasticsearchDirectoryReader

      public static ElasticsearchDirectoryReader getElasticsearchDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
      Tries to unwrap the given reader until the first ElasticsearchDirectoryReader instance is found or null if no instance is found.