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.elasticsearch.test.ESTestCase
checkIndexFailures, DEFAULT_NAMED_WRITABLE_REGISTRY, DEFAULT_TEST_WORKER_ID, failureAndSuccessEvents, FIPS_SYSPROP, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, JODA_TIMEZONE_IDS, logger, MIN_PRIVATE_PORT, TEST_WORKER_SYS_PROPERTY, TEST_WORKER_VM_ID
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 allAggregator
s have been closed.static org.elasticsearch.search.aggregations.AggregationBuilder
aggCardinality(java.lang.String name)
Request an aggregation that returns theCardinalityUpperBound
that was passed to its ctor.protected org.elasticsearch.index.mapper.FieldMapper
buildMockFieldMapper(org.elasticsearch.index.mapper.MappedFieldType ft)
Build aFieldMapper
to create theMappingLookup
used for the aggs.void
cleanupReleasables()
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 intestSupportedFieldTypes()
.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 anAggregator
.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, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
Create a AggregationContext for testing anAggregator
.protected <A extends org.elasticsearch.search.aggregations.Aggregator>
AcreateAggregator(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>
AcreateAggregator(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.search.aggregations.support.AggregationContext context)
protected org.elasticsearch.index.IndexSettings
createIndexSettings()
protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType
dateField(java.lang.String name, org.elasticsearch.index.mapper.DateFieldMapper.Resolution resolution)
Make a DateFieldMapper.DateFieldType for adate
.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 adouble
.protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType
geoPointField(java.lang.String name)
Make a GeoPointFieldMapper.GeoPointFieldType for ageo_point
.protected org.elasticsearch.script.ScriptService
getMockScriptService()
Sub-tests that need scripting can override this method to provide a script service and pre-baked scriptsprotected 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 ofValuesSourceType
that the aggregator supports.void
initValuesSourceRegistry()
protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType
keywordField(java.lang.String name)
Make a DateFieldMapper.DateFieldType for adate
.protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType
longField(java.lang.String name)
Make a NumberFieldMapper.NumberFieldType for along
.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, likeLuceneTestCase.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, likeLuceneTestCase.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 java.util.List<org.elasticsearch.index.mapper.ObjectMapper>
objectMappers()
ObjectMapper
s to add to the lookup.protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType
rangeField(java.lang.String name, org.elasticsearch.index.mapper.RangeType rangeType)
Make a NumberFieldMapper.NumberFieldType for arange
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce(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>
AsearchAndReduce(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>
AsearchAndReduce(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 queryQuery
and returns the reducedInternalAggregation
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce(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 queryQuery
and returns the reducedInternalAggregation
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation, C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce(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>
voidtestCase(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 inIndicesModule
(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 <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation>
voidverifyOutputFieldNames(T aggregationBuilder, V agg)
protected void
withAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.common.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,java.io.IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher,org.elasticsearch.search.aggregations.Aggregator,java.io.IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes)
protected org.apache.lucene.index.IndexReader
wrapDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
Override to wrap the DirectoryReader for aggs likeNestedAggregationBuilder
.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, createDefaultIndexAnalyzers, 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, newEnvironment, newEnvironment, newNodeEnvironment, newNodeEnvironment, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomDateFormatterPattern, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomNonNegativeByte, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, 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
-
AggregatorTestCase
public AggregatorTestCase()
-
-
Method Details
-
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 searcher, 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 builder, org.elasticsearch.search.aggregations.support.AggregationContext context) throws java.io.IOException- Throws:
java.io.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 java.io.IOExceptionCreate a AggregationContext for testing anAggregator
. While AggregationContext isReleasable
the caller is not responsible for releasing it. Instead, it is released automatically in incleanupReleasables()
.- Throws:
java.io.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, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOExceptionCreate a AggregationContext for testing anAggregator
. While AggregationContext isReleasable
the caller is not responsible for releasing it. Instead, it is released automatically in incleanupReleasables()
.- Throws:
java.io.IOException
-
buildMockFieldMapper
protected org.elasticsearch.index.mapper.FieldMapper buildMockFieldMapper(org.elasticsearch.index.mapper.MappedFieldType ft)Build aFieldMapper
to create theMappingLookup
used for the aggs.protected
so subclasses can have it. -
objectMappers
protected java.util.List<org.elasticsearch.index.mapper.ObjectMapper> objectMappers()ObjectMapper
s to add to the lookup. By default we don't need anyObjectMapper
s 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 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.IOExceptionCollects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
.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:
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, boolean splitLeavesIntoSeparateAggregators, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOExceptionCollects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
.- Parameters:
splitLeavesIntoSeparateAggregators
- If true this creates a newAggregator
for each leaf as though it were a separate index. If false this aggregates all leaves together, like we do in production.- 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
-
withAggregator
protected void withAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.common.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter,java.io.IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher,org.elasticsearch.search.aggregations.Aggregator,java.io.IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws java.io.IOException- Throws:
java.io.IOException
-
verifyOutputFieldNames
protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder, V extends org.elasticsearch.search.aggregations.InternalAggregation> void verifyOutputFieldNames(T aggregationBuilder, V agg) 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.IOExceptionOverride to wrap the DirectoryReader for aggs likeNestedAggregationBuilder
.- 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, likeLuceneTestCase.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.IOExceptionAdded to randomly run with more assertions on the index reader level, likeLuceneTestCase.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 ofValuesSourceType
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 intestSupportedFieldTypes()
. 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 bygetSupportedValuesSourceTypes()
, which must also be implemented.- Parameters:
fieldType
- the type of the field that will be testedfieldName
- 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.IOExceptionThis test will validate that an aggregator succeeds or fails to run against all the field types that are registered inIndicesModule
(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
-
cleanupReleasables
public void cleanupReleasables() -
afterClose
protected void afterClose()Hook for checking things after allAggregator
s 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 adate
. -
doubleField
protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType doubleField(java.lang.String name)Make a NumberFieldMapper.NumberFieldType for adouble
. -
geoPointField
protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType geoPointField(java.lang.String name)Make a GeoPointFieldMapper.GeoPointFieldType for ageo_point
. -
keywordField
protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType keywordField(java.lang.String name)Make a DateFieldMapper.DateFieldType for adate
. -
longField
protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType longField(java.lang.String name)Make a NumberFieldMapper.NumberFieldType for along
. -
rangeField
protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType rangeField(java.lang.String name, org.elasticsearch.index.mapper.RangeType rangeType)Make a NumberFieldMapper.NumberFieldType for arange
. -
aggCardinality
public static org.elasticsearch.search.aggregations.AggregationBuilder aggCardinality(java.lang.String name)Request an aggregation that returns theCardinalityUpperBound
that was passed to its ctor.
-