Class ElasticsearchMergePolicy


  • public final class ElasticsearchMergePolicy
    extends FilterMergePolicy
    A MergePolicy that upgrades segments and can upgrade merges.

    It can be useful to use the background merging process to upgrade segments, for example when we perform internal changes that imply different index options or when a user modifies his mapping in non-breaking ways: we could imagine using this merge policy to be able to add doc values to fields after the fact or on the opposite to remove them.

    For now, this MergePolicy takes care of moving versions that used to be stored as payloads to numeric doc values.

    • Constructor Detail

      • ElasticsearchMergePolicy

        public ElasticsearchMergePolicy​(MergePolicy delegate)
        Parameters:
        delegate - the merge policy to wrap
    • Method Detail

      • findForcedMerges

        public MergePolicy.MergeSpecification findForcedMerges​(SegmentInfos segmentInfos,
                                                               int maxSegmentCount,
                                                               Map<SegmentCommitInfo,​Boolean> segmentsToMerge,
                                                               MergePolicy.MergeContext mergeContext)
                                                        throws IOException
        Description copied from class: MergePolicy
        Determine what set of merge operations is necessary in order to merge to <= the specified segment count. IndexWriter calls this when its IndexWriter.forceMerge(int) method is called. This call is always synchronized on the IndexWriter instance so only one thread at a time will call this method.
        Overrides:
        findForcedMerges in class FilterMergePolicy
        Parameters:
        segmentInfos - the total set of segments in the index
        maxSegmentCount - requested maximum number of segments in the index (currently this is always 1)
        segmentsToMerge - contains the specific SegmentInfo instances that must be merged away. This may be a subset of all SegmentInfos. If the value is True for a given SegmentInfo, that means this segment was an original segment present in the to-be-merged index; else, it was a segment produced by a cascaded merge.
        mergeContext - the IndexWriter to find the merges on
        Throws:
        IOException
      • setUpgradeInProgress

        public void setUpgradeInProgress​(boolean upgrade,
                                         boolean onlyAncientSegments)
        When upgrade is true, running a force merge will upgrade any segments written with older versions. This will apply to the next call to IndexWriter.forceMerge(int) that is handled by this MergePolicy, as well as cascading calls made by IndexWriter.