Class AggregatorTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.search.aggregations.AggregatorTestCase
Direct Known Subclasses:
GeoGridAggregatorTestCase

public abstract class AggregatorTestCase extends ESTestCase
Base class for testing Aggregator implementations. Provides helpers for constructing and searching an Aggregator implementation based on a provided AggregationBuilder instance.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     

    Nested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase

    ESTestCase.DeprecationWarning, ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis

    Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase

    org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.elasticsearch.search.aggregations.support.ValuesSourceRegistry
     

    Fields inherited from class org.apache.lucene.util.LuceneTestCase

    assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_BADAPPLES, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Hook for checking things after all Aggregators have been closed.
    static org.elasticsearch.search.aggregations.AggregationBuilder
    Request an aggregation that returns the CardinalityUpperBound that was passed to its ctor.
    protected org.elasticsearch.index.mapper.FieldMapper
    buildMockFieldMapper(org.elasticsearch.index.mapper.MappedFieldType ft)
    Build a FieldMapper to create the MappingLookup used for the aggs.
    void
     
    protected org.elasticsearch.search.aggregations.AggregationBuilder
    createAggBuilderForTypeTest(org.elasticsearch.index.mapper.MappedFieldType fieldType, String fieldName)
    This method is invoked each time a field type is tested in testSupportedFieldTypes().
    protected org.elasticsearch.search.aggregations.support.AggregationContext
    createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.apache.lucene.search.Query query, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Create a AggregationContext for testing an Aggregator.
    protected org.elasticsearch.search.aggregations.support.AggregationContext
    createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService, long bytesToPreallocate, int maxBucket, boolean isInSortOrderExecutionRequired, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Create a AggregationContext for testing an Aggregator.
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.search.aggregations.support.AggregationContext context)
     
    protected org.elasticsearch.indices.analysis.AnalysisModule
     
    protected org.elasticsearch.index.IndexSettings
     
    protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType
    dateField(String name, org.elasticsearch.index.mapper.DateFieldMapper.Resolution resolution)
    Make a DateFieldMapper.DateFieldType for a date.
    protected <R extends org.elasticsearch.search.aggregations.InternalAggregation>
    void
    debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.common.TriConsumer<R,Class<? extends org.elasticsearch.search.aggregations.Aggregator>,Map<String,Map<String,Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Execute and aggregation and collect its debug information.
    protected <R extends org.elasticsearch.search.aggregations.InternalAggregation>
    void
    debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.common.TriConsumer<R,Class<? extends org.elasticsearch.search.aggregations.Aggregator>,Map<String,Map<String,Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Execute and aggregation and collect its debug information.
    protected void
    doAssertReducedMultiBucketConsumer(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)
     
    protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType
    Make a NumberFieldMapper.NumberFieldType for a double.
    protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType
    Make a GeoPointFieldMapper.GeoPointFieldType for a geo_point.
    protected org.elasticsearch.script.ScriptService
    Sub-tests that need scripting can override this method to provide a script service and pre-baked scripts
    protected List<org.elasticsearch.plugins.SearchPlugin>
    Test cases should override this if they have plugins that need to be loaded, e.g.
    protected List<org.elasticsearch.search.aggregations.support.ValuesSourceType>
    Implementors should return a list of ValuesSourceType that the aggregator supports.
    void
     
    final void
     
    protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType
    Make a DateFieldMapper.DateFieldType for a date.
    protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType
    Make a NumberFieldMapper.NumberFieldType for a long.
    protected static org.apache.lucene.index.IndexReader
    maybeWrapReaderEs(org.apache.lucene.index.DirectoryReader reader)
    Added to randomly run with more assertions on the index reader level, like LuceneTestCase.wrapReader(IndexReader), which can't be used because it also wraps in the IndexReader with other implementations that we can't handle.
    protected static org.apache.lucene.search.IndexSearcher
    newIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
    Added to randomly run with more assertions on the index searcher level, like LuceneTestCase.newSearcher(IndexReader), which can't be used because it also wraps in the IndexSearcher's IndexReader with other implementations that we can't handle.
    protected List<org.elasticsearch.index.mapper.ObjectMapper>
    ObjectMappers to add to the lookup.
    protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType
    rangeField(String name, org.elasticsearch.index.mapper.RangeType rangeType)
    Make a NumberFieldMapper.NumberFieldType for a range.
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean splitLeavesIntoSeparateAggregators, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Collects all documents that match the provided query Query and returns the reduced InternalAggregation.
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Collects all documents that match the provided query Query and returns the reduced InternalAggregation.
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation>
    void
    testCase(T aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, Consumer<V> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    void
    This test will validate that an aggregator succeeds or fails to run against all the field types that are registered in IndicesModule (e.g.
    protected List<String>
    A method that allows implementors to specifically blacklist particular field types (based on their content_name).
    protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation>
    void
    verifyOutputFieldNames(T aggregationBuilder, V agg)
     
    protected void
    withAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher,org.elasticsearch.search.aggregations.Aggregator,IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected void
    withIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher,IOException> consume)
     
    protected void
    withNonMergingIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher,IOException> consume)
     
    protected org.apache.lucene.index.IndexReader
    wrapDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
    Override to wrap the DirectoryReader for aggs like NestedAggregationBuilder.
    protected static org.apache.lucene.index.DirectoryReader
    wrapInMockESDirectoryReader(org.apache.lucene.index.DirectoryReader directoryReader)
     
    protected final org.elasticsearch.common.io.stream.NamedWriteableRegistry
    The NamedWriteableRegistry to use for this test.

    Methods inherited from class org.elasticsearch.test.ESTestCase

    after, afterIfFailed, afterIfSuccessful, assertArrayEquals, assertBusy, assertBusy, assertCriticalWarnings, assertEquals, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, compatibleMediaType, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createParserWithCompatibilityFor, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureNoWarnings, ensureSupportedLocale, filteredWarnings, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newEnvironment, newEnvironment, newNodeEnvironment, newNodeEnvironment, parserConfig, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomCompatibleMediaType, randomDateFormatterPattern, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomMap, randomMillisUpToYear9999, randomNonNegativeByte, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomVendorType, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffleMap, shuffleXContent, shuffleXContent, skipTestWaitingForLuceneFix, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, xContentRegistry

    Methods inherited from class org.apache.lucene.util.LuceneTestCase

    addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newSearcher, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, slowFileExists, tearDown, usually, usually, wrapReader

    Methods inherited from class org.junit.Assert

    assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • valuesSourceRegistry

      protected org.elasticsearch.search.aggregations.support.ValuesSourceRegistry valuesSourceRegistry
  • Constructor Details

    • AggregatorTestCase

      public AggregatorTestCase()
  • Method Details

    • initPlugins

      public final void initPlugins()
    • initAnalysisRegistry

      public void initAnalysisRegistry() throws Exception
      Throws:
      Exception
    • createAnalysisModule

      protected org.elasticsearch.indices.analysis.AnalysisModule createAnalysisModule() throws Exception
      Returns:
      a new analysis module. Tests that require a fully constructed analysis module (used to create an analysis registry) should override this method
      Throws:
      Exception
    • getSearchPlugins

      protected List<org.elasticsearch.plugins.SearchPlugin> getSearchPlugins()
      Test cases should override this if they have plugins that need to be loaded, e.g. the plugins their aggregators are in.
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.search.aggregations.support.AggregationContext context) throws IOException
      Throws:
      IOException
    • createAggregationContext

      protected org.elasticsearch.search.aggregations.support.AggregationContext createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.apache.lucene.search.Query query, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Create a AggregationContext for testing an Aggregator. While AggregationContext is Releasable the caller is not responsible for releasing it. Instead, it is released automatically in in cleanupReleasables().
      Throws:
      IOException
    • createAggregationContext

      protected org.elasticsearch.search.aggregations.support.AggregationContext createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService, long bytesToPreallocate, int maxBucket, boolean isInSortOrderExecutionRequired, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Create a AggregationContext for testing an Aggregator. While AggregationContext is Releasable the caller is not responsible for releasing it. Instead, it is released automatically in in cleanupReleasables().
      Throws:
      IOException
    • buildMockFieldMapper

      protected org.elasticsearch.index.mapper.FieldMapper buildMockFieldMapper(org.elasticsearch.index.mapper.MappedFieldType ft)
      Build a FieldMapper to create the MappingLookup used for the aggs. protected so subclasses can have it.
    • objectMappers

      protected List<org.elasticsearch.index.mapper.ObjectMapper> objectMappers()
      ObjectMappers to add to the lookup. By default we don't need any ObjectMappers but testing nested objects will require adding some.
    • createIndexSettings

      protected org.elasticsearch.index.IndexSettings createIndexSettings()
    • getMockScriptService

      protected org.elasticsearch.script.ScriptService getMockScriptService()
      Sub-tests that need scripting can override this method to provide a script service and pre-baked scripts
    • searchAndReduce

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Collects all documents that match the provided query Query and returns the reduced InternalAggregation.

      Half the time it aggregates each leaf individually and reduces all results together. The other half the time it aggregates across the entire index at once and runs a final reduction on the single resulting agg.

      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean splitLeavesIntoSeparateAggregators, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Collects all documents that match the provided query Query and returns the reduced InternalAggregation. It runs the aggregation as well using a circuit breaker that randomly throws CircuitBreakingException in order to mak sure the implementation does not leak.
      Parameters:
      splitLeavesIntoSeparateAggregators - If true this creates a new Aggregator for each leaf as though it were a separate index. If false this aggregates all leaves together, like we do in production.
      Throws:
      IOException
    • doAssertReducedMultiBucketConsumer

      protected void doAssertReducedMultiBucketConsumer(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)
    • testCase

      protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation> void testCase(T aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, Consumer<V> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • withIndex

      protected void withIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher,IOException> consume) throws IOException
      Throws:
      IOException
    • withNonMergingIndex

      protected void withNonMergingIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher,IOException> consume) throws IOException
      Throws:
      IOException
    • debugTestCase

      protected <R extends org.elasticsearch.search.aggregations.InternalAggregation> void debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.common.TriConsumer<R,Class<? extends org.elasticsearch.search.aggregations.Aggregator>,Map<String,Map<String,Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Execute and aggregation and collect its debug information. Unlike testCase(T, org.apache.lucene.search.Query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, java.io.IOException>, java.util.function.Consumer<V>, org.elasticsearch.index.mapper.MappedFieldType...) this doesn't randomly create an Aggregator per leaf and perform partial reductions. It always creates a single Aggregator so we can get consistent debug info.
      Throws:
      IOException
    • debugTestCase

      protected <R extends org.elasticsearch.search.aggregations.InternalAggregation> void debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.common.TriConsumer<R,Class<? extends org.elasticsearch.search.aggregations.Aggregator>,Map<String,Map<String,Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Execute and aggregation and collect its debug information. Unlike testCase(T, org.apache.lucene.search.Query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, java.io.IOException>, java.util.function.Consumer<V>, org.elasticsearch.index.mapper.MappedFieldType...) this doesn't randomly create an Aggregator per leaf and perform partial reductions. It always creates a single Aggregator so we can get consistent debug info.
      Throws:
      IOException
    • withAggregator

      protected void withAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher,org.elasticsearch.search.aggregations.Aggregator,IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • verifyOutputFieldNames

      protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation> void verifyOutputFieldNames(T aggregationBuilder, V agg) throws IOException
      Throws:
      IOException
    • wrapDirectoryReader

      protected org.apache.lucene.index.IndexReader wrapDirectoryReader(org.apache.lucene.index.DirectoryReader reader) throws IOException
      Override to wrap the DirectoryReader for aggs like NestedAggregationBuilder.
      Throws:
      IOException
    • wrapInMockESDirectoryReader

      protected static org.apache.lucene.index.DirectoryReader wrapInMockESDirectoryReader(org.apache.lucene.index.DirectoryReader directoryReader) throws IOException
      Throws:
      IOException
    • newIndexSearcher

      protected static org.apache.lucene.search.IndexSearcher newIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
      Added to randomly run with more assertions on the index searcher level, like LuceneTestCase.newSearcher(IndexReader), which can't be used because it also wraps in the IndexSearcher's IndexReader with other implementations that we can't handle. (e.g. ParallelCompositeReader)
    • maybeWrapReaderEs

      protected static org.apache.lucene.index.IndexReader maybeWrapReaderEs(org.apache.lucene.index.DirectoryReader reader) throws IOException
      Added to randomly run with more assertions on the index reader level, like LuceneTestCase.wrapReader(IndexReader), which can't be used because it also wraps in the IndexReader with other implementations that we can't handle. (e.g. ParallelCompositeReader)
      Throws:
      IOException
    • getSupportedValuesSourceTypes

      protected List<org.elasticsearch.search.aggregations.support.ValuesSourceType> getSupportedValuesSourceTypes()
      Implementors should return a list of ValuesSourceType that the aggregator supports. This is used to test the matrix of supported/unsupported field types against the aggregator and verify it works (or doesn't) as expected. If this method is implemented, createAggBuilderForTypeTest(MappedFieldType, String) should be implemented as well.
      Returns:
      list of supported ValuesSourceTypes
    • createAggBuilderForTypeTest

      protected org.elasticsearch.search.aggregations.AggregationBuilder createAggBuilderForTypeTest(org.elasticsearch.index.mapper.MappedFieldType fieldType, String fieldName)
      This method is invoked each time a field type is tested in testSupportedFieldTypes(). The field type and name are provided, and the implementor is expected to return an AggBuilder accordingly. The AggBuilder should be returned even if the aggregation does not support the field type, because the test will check if an exception is thrown in that case. The list of supported types are provided by getSupportedValuesSourceTypes(), which must also be implemented.
      Parameters:
      fieldType - the type of the field that will be tested
      fieldName - the name of the field that will be test
      Returns:
      an aggregation builder to test against the field
    • unsupportedMappedFieldTypes

      protected List<String> unsupportedMappedFieldTypes()
      A method that allows implementors to specifically blacklist particular field types (based on their content_name). This is needed in some areas where the ValuesSourceType is not granular enough, for example integer values vs floating points, or `keyword` bytes vs `binary` bytes (which are not searchable) This is a blacklist instead of a whitelist because there are vastly more field types than ValuesSourceTypes, and it's expected that these unsupported cases are exceptional rather than common
    • testSupportedFieldTypes

      public void testSupportedFieldTypes() throws IOException
      This test will validate that an aggregator succeeds or fails to run against all the field types that are registered in IndicesModule (e.g. all the core field types). An aggregator is provided by the implementor class, and it is executed against each field type in turn. If an exception is thrown when the field is supported, that will fail the test. Similarly, if an exception _is not_ thrown when a field is unsupported, that will also fail the test. Exception types/messages are not currently checked, just presence/absence of an exception.
      Throws:
      IOException
    • cleanupReleasables

      public void cleanupReleasables()
    • afterClose

      protected void afterClose()
      Hook for checking things after all Aggregators have been closed.
    • dateField

      protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType dateField(String name, org.elasticsearch.index.mapper.DateFieldMapper.Resolution resolution)
      Make a DateFieldMapper.DateFieldType for a date.
    • doubleField

      protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType doubleField(String name)
      Make a NumberFieldMapper.NumberFieldType for a double.
    • geoPointField

      protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType geoPointField(String name)
      Make a GeoPointFieldMapper.GeoPointFieldType for a geo_point.
    • keywordField

      protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType keywordField(String name)
      Make a DateFieldMapper.DateFieldType for a date.
    • longField

      protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType longField(String name)
      Make a NumberFieldMapper.NumberFieldType for a long.
    • rangeField

      protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType rangeField(String name, org.elasticsearch.index.mapper.RangeType rangeType)
      Make a NumberFieldMapper.NumberFieldType for a range.
    • writableRegistry

      protected final org.elasticsearch.common.io.stream.NamedWriteableRegistry writableRegistry()
      Description copied from class: ESTestCase
      The NamedWriteableRegistry to use for this test. Subclasses should override and use liberally.
      Overrides:
      writableRegistry in class ESTestCase
    • aggCardinalityUpperBound

      public static org.elasticsearch.search.aggregations.AggregationBuilder aggCardinalityUpperBound(String name)
      Request an aggregation that returns the CardinalityUpperBound that was passed to its ctor.