Class AggregatorTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.search.aggregations.AggregatorTestCase

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  AggregatorTestCase.InternalAggCardinality  

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

    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 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
    AggregatorTestCase()  
  • Method Summary

    Modifier and Type Method Description
    protected void afterClose()
    Hook for checking things after all Aggregators have been closed.
    static org.elasticsearch.search.aggregations.AggregationBuilder aggCardinality​(java.lang.String name)
    Request an aggregation that returns the CardinalityUpperBound that was passed to its ctor.
    protected org.elasticsearch.search.aggregations.AggregationBuilder createAggBuilderForTypeTest​(org.elasticsearch.index.mapper.MappedFieldType fieldType, java.lang.String fieldName)
    This method is invoked each time a field type is tested in testSupportedFieldTypes().
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected <A extends org.elasticsearch.search.aggregations.Aggregator>
    A
    createAggregator​(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.elasticsearch.search.internal.SearchContext searchContext)  
    protected org.elasticsearch.index.IndexSettings createIndexSettings()  
    protected org.elasticsearch.search.internal.SearchContext createSearchContext​(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Create a SearchContext for testing an Aggregator.
    protected org.elasticsearch.search.internal.SearchContext createSearchContext​(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType dateField​(java.lang.String name, org.elasticsearch.index.mapper.DateFieldMapper.Resolution resolution)
    Make a DateFieldMapper.DateFieldType for a date.
    protected void doAssertReducedMultiBucketConsumer​(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)  
    protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType doubleField​(java.lang.String name)
    Make a NumberFieldMapper.NumberFieldType for a double.
    protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType geoPointField​(java.lang.String name)
    Make a GeoPointFieldMapper.GeoPointFieldType for a geo_point.
    protected java.util.Map<java.lang.String,​org.elasticsearch.index.mapper.MappedFieldType> getFieldAliases​(org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Allows subclasses to provide alternate names for the provided field type, which can be useful when testing aggregations on field aliases.
    protected java.util.function.BiFunction<org.elasticsearch.index.mapper.MappedFieldType,​java.lang.String,​org.elasticsearch.index.fielddata.IndexFieldData<?>> getIndexFieldDataLookup​(org.elasticsearch.index.mapper.MapperService mapperService, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService)
    Sub-tests that need a more complex index field data provider can override this
    protected org.elasticsearch.script.ScriptService getMockScriptService()
    Sub-tests that need scripting can override this method to provide a script service and pre-baked scripts
    protected java.util.List<org.elasticsearch.plugins.SearchPlugin> getSearchPlugins()
    Test cases should override this if they have plugins that need to be loaded, e.g.
    protected java.util.List<org.elasticsearch.search.aggregations.support.ValuesSourceType> getSupportedValuesSourceTypes()
    Implementors should return a list of ValuesSourceType that the aggregator supports.
    void initValuesSourceRegistry()  
    protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType keywordField​(java.lang.String name)
    Make a DateFieldMapper.DateFieldType for a date.
    protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType longField​(java.lang.String name)
    Make a NumberFieldMapper.NumberFieldType for a long.
    protected org.elasticsearch.index.mapper.MapperService mapperServiceMock()
    sub-tests that need a more complex mock can overwrite this
    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 org.elasticsearch.index.query.QueryShardContext queryShardContextMock​(org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MapperService mapperService, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService, org.elasticsearch.common.util.BigArrays bigArrays)
    sub-tests that need a more complex mock can overwrite this
    protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType rangeField​(java.lang.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
    search​(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
    search​(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
    search​(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)  
    protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,​ C extends org.elasticsearch.search.aggregations.Aggregator>
    A
    search​(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 <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, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
    Divides the provided IndexSearcher in sub-searcher, one for each segment, builds an aggregator for each sub-searcher filtered by the provided 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.common.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,​java.io.IOException> buildIndex, java.util.function.Consumer<V> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)  
    void testSupportedFieldTypes()
    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 java.util.List<java.lang.String> unsupportedMappedFieldTypes()
    A method that allows implementors to specifically blacklist particular field types (based on their content_name).
    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)  

    Methods inherited from class org.elasticsearch.test.ESTestCase

    after, afterIfFailed, afterIfSuccessful, allowedWarnings, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, clearAdditionalRoles, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createParser, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableJodaDeprecationWarningsCheck, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBoolean, randomByte, randomByteArrayOfLength, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomZone, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, writableRegistry, 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, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, 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, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, restoreSpins, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, setupSpins, 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

  • Method Details

    • getFieldAliases

      protected java.util.Map<java.lang.String,​org.elasticsearch.index.mapper.MappedFieldType> getFieldAliases​(org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
      Allows subclasses to provide alternate names for the provided field type, which can be useful when testing aggregations on field aliases.
    • initValuesSourceRegistry

      public void initValuesSourceRegistry()
    • getSearchPlugins

      protected java.util.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 indexSearcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator​(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator​(org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createAggregator

      protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator​(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.elasticsearch.search.internal.SearchContext searchContext) throws java.io.IOException
      Throws:
      java.io.IOException
    • createSearchContext

      protected org.elasticsearch.search.internal.SearchContext createSearchContext​(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Create a SearchContext for testing an Aggregator.
      Throws:
      java.io.IOException
    • createSearchContext

      protected org.elasticsearch.search.internal.SearchContext createSearchContext​(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • createIndexSettings

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

      protected org.elasticsearch.index.mapper.MapperService mapperServiceMock()
      sub-tests that need a more complex mock can overwrite this
    • queryShardContextMock

      protected org.elasticsearch.index.query.QueryShardContext queryShardContextMock​(org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MapperService mapperService, org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService, org.elasticsearch.common.util.BigArrays bigArrays)
      sub-tests that need a more complex mock can overwrite this
    • getIndexFieldDataLookup

      protected java.util.function.BiFunction<org.elasticsearch.index.mapper.MappedFieldType,​java.lang.String,​org.elasticsearch.index.fielddata.IndexFieldData<?>> getIndexFieldDataLookup​(org.elasticsearch.index.mapper.MapperService mapperService, org.elasticsearch.indices.breaker.CircuitBreakerService circuitBreakerService)
      Sub-tests that need a more complex index field data provider can override this
    • 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
    • search

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,​ C extends org.elasticsearch.search.aggregations.Aggregator> A search​(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 java.io.IOException
      Throws:
      java.io.IOException
    • search

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,​ C extends org.elasticsearch.search.aggregations.Aggregator> A search​(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 java.io.IOException
      Throws:
      java.io.IOException
    • search

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,​ C extends org.elasticsearch.search.aggregations.Aggregator> A search​(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 java.io.IOException
      Throws:
      java.io.IOException
    • search

      protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,​ C extends org.elasticsearch.search.aggregations.Aggregator> A search​(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 java.io.IOException
      Throws:
      java.io.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, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.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 java.io.IOException
      Throws:
      java.io.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 java.io.IOException
      Throws:
      java.io.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 java.io.IOException
      Divides the provided IndexSearcher in sub-searcher, one for each segment, builds an aggregator for each sub-searcher filtered by the provided Query and returns the reduced InternalAggregation.
      Throws:
      java.io.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.common.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,​java.io.IOException> buildIndex, java.util.function.Consumer<V> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException
      Throws:
      java.io.IOException
    • wrapDirectoryReader

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

      protected static org.apache.lucene.index.DirectoryReader wrapInMockESDirectoryReader​(org.apache.lucene.index.DirectoryReader directoryReader) throws java.io.IOException
      Throws:
      java.io.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 java.io.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:
      java.io.IOException
    • getSupportedValuesSourceTypes

      protected java.util.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, java.lang.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 java.util.List<java.lang.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 java.io.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:
      java.io.IOException
    • afterClose

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

      protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType dateField​(java.lang.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​(java.lang.String name)
      Make a NumberFieldMapper.NumberFieldType for a double.
    • geoPointField

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

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

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

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

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