Package org.elasticsearch.index.mapper
Class MapperTestCase
java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.index.mapper.MapperServiceTestCase
org.elasticsearch.index.mapper.MapperTestCase
Base class for testing
Mapper
s.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An example of a malformed value.protected class
class
static final record
static final record
static interface
Nested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase
ESTestCase.DeprecationWarning, ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis, ESTestCase.WithoutSecurityManager
Nested classes/interfaces inherited from class org.apache.lucene.tests.util.LuceneTestCase
org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix, org.apache.lucene.tests.util.LuceneTestCase.BadApple, org.apache.lucene.tests.util.LuceneTestCase.Monster, org.apache.lucene.tests.util.LuceneTestCase.Nightly, org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.tests.util.LuceneTestCase.SuppressFsync, org.apache.lucene.tests.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.tests.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.tests.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.tests.util.LuceneTestCase.ThrowingConsumer<T extends Object>, org.apache.lucene.tests.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.tests.util.LuceneTestCase.Weekly
-
Field Summary
Fields inherited from class org.elasticsearch.index.mapper.MapperServiceTestCase
INCLUDE_DEFAULTS, SETTINGS
Fields inherited from class org.elasticsearch.test.ESTestCase
checkIndexFailures, DEFAULT_TEST_WORKER_ID, failureAndSuccessEvents, FIPS_SYSPROP, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, logger, MIN_PRIVATE_PORT, TEST_WORKER_SYS_PROPERTY, TEST_WORKER_VM_ID
Fields inherited from class org.apache.lucene.tests.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_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_THROTTLING, TEST_WEEKLY, VERBOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
protected boolean
protected void
protected <T> void
assertDimension
(boolean isDimension, Function<T, Boolean> checker) protected void
assertExistsQuery
(MappedFieldType fieldType, org.apache.lucene.search.Query query, LuceneDocument fields) protected void
assertExistsQuery
(MapperService mapperService) protected void
assertFetch
(MapperService mapperService, String field, Object value, String format) Assert that fetching a value usingMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produces the same value as fetching using doc values.protected static void
assertHasNorms
(LuceneDocument doc, String field) protected <T> void
assertMetricType
(String metricType, Function<T, Enum<TimeSeriesParams.MetricType>> checker) protected static void
assertNoDocValuesField
(LuceneDocument doc, String field) protected static void
protected final void
protected final void
protected final void
assertScriptDocValues
(MapperService mapperService, Object sourceValue, org.hamcrest.Matcher<List<?>> dvMatcher) protected void
assertSearchable
(MappedFieldType fieldType) protected final <T> T
compileScript
(Script script, ScriptContext<T> context) This is the injection point for tests that require mock scripts.protected boolean
A few field types (e.g.protected final MapperTestCase.ExampleMalformedValue
exampleMalformedValue
(String value) Build anMapperTestCase.ExampleMalformedValue
that parses a string.protected final MapperTestCase.ExampleMalformedValue
exampleMalformedValue
(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.xcontent.XContentBuilder, IOException> value) Build anMapperTestCase.ExampleMalformedValue
for arbitrary xcontent.protected List<MapperTestCase.ExampleMalformedValue>
Some example of malformed values and matches for exceptions that parsing them should create.protected final List<?>
fetchFromDocValues
(MapperService mapperService, MappedFieldType ft, DocValueFormat format, Object sourceValue) Use a ValueFetcher to extract values from doc values.protected abstract Object
Create a random_source
value for this field.protected String[]
protected String[]
protected abstract Object
Returns a sample value for the field, to be used in a documentprotected Object
Returns a sample value for the field, to be used when querying the field.protected abstract MapperTestCase.IngestScriptSupport
protected void
metaMapping
(org.elasticsearch.xcontent.XContentBuilder b) protected String
protected abstract void
minimalMapping
(org.elasticsearch.xcontent.XContentBuilder b) protected void
minimalStoreMapping
(org.elasticsearch.xcontent.XContentBuilder b) protected void
randomFetchTestFieldConfig
(org.elasticsearch.xcontent.XContentBuilder b) Field configuration fortestFetch()
andtestFetchMany()
.protected String
A random format to use when tripping intestFetch()
andtestFetchMany()
.protected final MapperService
protected void
Test that dimension parameter is not updateableprotected abstract void
protected boolean
Override to disable testingcopy_to
in fields that don't support it.protected boolean
protected abstract boolean
Does this field mapper supportignore_malformed
?protected boolean
Override to disable testingmeta
in fields that don't support it.protected boolean
protected boolean
protected abstract MapperTestCase.SyntheticSourceSupport
syntheticSourceSupport
(boolean ignoreMalformed) void
final void
final void
final void
final void
final void
This test verifies that the exists query created is the appropriate one, and aligns with the data structures being created for a document with a value for the field.final void
Asserts that fetching a single value from doc values and from the nativeMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produce the same results.final void
Asserts that fetching many values from doc values and from the nativeMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produce the same results.final void
final void
final void
final void
Checks that field data from this field produces the same values for query-time scripts and for index-time scriptsfinal void
Checks that loading stored fields for this field produces the same set of values for query time scripts and index time scriptsfinal void
testMeta()
final void
final void
final void
final void
final void
final void
final void
final void
final void
final void
final void
final void
final void
void
protected void
writeField
(org.elasticsearch.xcontent.XContentBuilder builder) Writes the field and a sample value for it to the providedXContentBuilder
.Methods inherited from class org.elasticsearch.index.mapper.MapperServiceTestCase
createDocumentMapper, createDocumentMapper, createDocumentMapper, createIndexAnalyzers, createIndexAnalyzers, createIndexSettings, createMapperService, createMapperService, createMapperService, createMapperService, createMapperService, createMapperService, createMapperService, createMapperService, createSearchExecutionContext, createSearchExecutionContext, createSearchExecutionContext, createTimeSeriesModeDocumentMapper, dynamicMapping, fieldDataLookup, fieldDataLookup, fieldMapping, getIndexSettings, getIndexSettingsBuilder, getPlugins, getVersion, mapping, mappingNoSubobjects, merge, merge, merge, merge, randomIndexOptions, runtimeFieldMapping, runtimeMapping, source, source, source, source, syntheticSource, syntheticSourceFieldMapping, syntheticSourceMapping, syntheticSourceStoredFieldLoader, topMapping, validateRoundTripReader, withAggregationContext, withAggregationContext, withAggregationContext, withAggregationContext, withLuceneIndex
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, copyInstance, copyNamedWriteable, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createParserWithCompatibilityFor, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureNoWarnings, ensureSupportedLocale, filteredWarnings, frequently, generateRandomStringArray, generateRandomStringArray, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, getWorkerBasePort, inFipsJvm, iterations, maybeRestoreClassSecurityManager, maybeSet, maybeStashClassSecurityManager, mockScript, newEnvironment, newEnvironment, newNodeEnvironment, newNodeEnvironment, parserConfig, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomCompatibleMediaType, randomDateFormatterPattern, randomDouble, randomDoubleBetween, randomDoubles, randomDoubles, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomIdentifier, randomInt, randomInt, randomIntBetween, randomInts, randomInts, randomIp, randomList, randomList, randomLong, randomLongBetween, randomLongs, randomLongs, randomMap, randomMillisUpToYear9999, randomNonEmptySubsetOf, randomNonNegativeByte, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomSet, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomVendorType, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, secureRandom, secureRandom, secureRandomFips, secureRandomFips, secureRandomNonFips, secureRandomNonFips, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffledList, shuffleMap, shuffleXContent, shuffleXContent, skipTestWaitingForLuceneFix, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, writableRegistry, xContentRegistry
Methods inherited from class org.apache.lucene.tests.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, getJvmForkArguments, 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
-
Constructor Details
-
MapperTestCase
public MapperTestCase()
-
-
Method Details
-
minimalMapping
protected abstract void minimalMapping(org.elasticsearch.xcontent.XContentBuilder b) throws IOException - Throws:
IOException
-
writeField
Writes the field and a sample value for it to the providedXContentBuilder
. To be overridden in case the field should not be written at all in documents, like in the case of runtime fields.- Throws:
IOException
-
getSampleValueForDocument
Returns a sample value for the field, to be used in a document -
getSampleValueForQuery
Returns a sample value for the field, to be used when querying the field. Normally this is the same format as what is indexed as part of a document, and returned bygetSampleValueForDocument()
, but there are cases where fields are queried differently frow how they are indexed e.g. token_count or runtime fields -
testExistsQueryMinimalMapping
This test verifies that the exists query created is the appropriate one, and aligns with the data structures being created for a document with a value for the field. This can only be verified for the minimal mapping. Field types that allow configurable doc_values or norms should write their own tests that creates the different mappings combinations and invokeassertExistsQuery(MapperService)
to verify the behaviour.- Throws:
IOException
-
testAggregatableConsistency
- Throws:
IOException
-
assertAggregatableConsistency
-
supportsIgnoreMalformed
protected abstract boolean supportsIgnoreMalformed()Does this field mapper supportignore_malformed
? -
exampleMalformedValue
Build anMapperTestCase.ExampleMalformedValue
that parses a string. -
exampleMalformedValue
protected final MapperTestCase.ExampleMalformedValue exampleMalformedValue(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.xcontent.XContentBuilder, IOException> value) Build anMapperTestCase.ExampleMalformedValue
for arbitrary xcontent. -
exampleMalformedValues
Some example of malformed values and matches for exceptions that parsing them should create. -
testIgnoreMalformedFalseByDefault
- Throws:
IOException
-
testIgnoreMalformedExplicitlyFalse
- Throws:
IOException
-
testIgnoreMalformedTrue
- Throws:
IOException
-
assertExistsQuery
- Throws:
IOException
-
assertExistsQuery
protected void assertExistsQuery(MappedFieldType fieldType, org.apache.lucene.search.Query query, LuceneDocument fields) -
assertNoFieldNamesField
-
assertHasNorms
-
assertNoDocValuesField
-
assertDimension
protected <T> void assertDimension(boolean isDimension, Function<T, Boolean> checker) throws IOException- Throws:
IOException
-
assertMetricType
protected <T> void assertMetricType(String metricType, Function<T, Enum<TimeSeriesParams.MetricType>> checker) throws IOException- Throws:
IOException
-
testEmptyName
public final void testEmptyName() -
testBlankName
public final void testBlankName() -
testMinimalSerializesToItself
- Throws:
IOException
-
testMinimalToMaximal
- Throws:
IOException
-
assertParseMinimalWarnings
protected final void assertParseMinimalWarnings() -
assertParseMaximalWarnings
protected final void assertParseMaximalWarnings() -
getParseMinimalWarnings
-
getParseMaximalWarnings
-
supportsMeta
protected boolean supportsMeta()Override to disable testingmeta
in fields that don't support it. -
supportsCopyTo
protected boolean supportsCopyTo()Override to disable testingcopy_to
in fields that don't support it. -
metaMapping
- Throws:
IOException
-
testMeta
- Throws:
IOException
-
testDeprecatedBoost
- Throws:
IOException
-
fetchFromDocValues
protected final List<?> fetchFromDocValues(MapperService mapperService, MappedFieldType ft, DocValueFormat format, Object sourceValue) throws IOException Use a ValueFetcher to extract values from doc values.- Throws:
IOException
-
assertScriptDocValues
protected final void assertScriptDocValues(MapperService mapperService, Object sourceValue, org.hamcrest.Matcher<List<?>> dvMatcher) throws IOException - Throws:
IOException
-
registerParameters
protected abstract void registerParameters(MapperTestCase.ParameterChecker checker) throws IOException - Throws:
IOException
-
testUpdates
- Throws:
IOException
-
testTextSearchInfoConsistency
- Throws:
IOException
-
assertSearchable
-
testFetch
Asserts that fetching a single value from doc values and from the nativeMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produce the same results.Generally this method covers many many random cases but rarely. So if it fails its generally a good idea to capture its randomized parameters into a new method so we can be sure we consistently test any unique and interesting failure case. See the tests for
DateFieldMapper
for some examples.- Throws:
IOException
-
testFetchMany
Asserts that fetching many values from doc values and from the nativeMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produce the same results.Generally this method covers many many random cases but rarely. So if it fails its generally a good idea to capture its randomized parameters into a new method so we can be sure we consistently test any unique and interesting failure case. See the tests for
DateFieldMapper
for some examples.- Throws:
IOException
-
randomFetchTestMapper
- Throws:
IOException
-
randomFetchTestFieldConfig
protected void randomFetchTestFieldConfig(org.elasticsearch.xcontent.XContentBuilder b) throws IOException Field configuration fortestFetch()
andtestFetchMany()
. Default implementation delegates tominimalMapping(org.elasticsearch.xcontent.XContentBuilder)
but can be overridden to randomize the field type and options.- Throws:
IOException
-
randomFetchTestFormat
A random format to use when tripping intestFetch()
andtestFetchMany()
. -
registerDimensionChecks
Test that dimension parameter is not updateable- Throws:
IOException
-
generateRandomInputValue
Create a random_source
value for this field. Must be compatible withXContentBuilder.value(Object)
and the field's parser. -
assertFetch
protected void assertFetch(MapperService mapperService, String field, Object value, String format) throws IOException Assert that fetching a value usingMappedFieldType.valueFetcher(org.elasticsearch.index.query.SearchExecutionContext, java.lang.String)
produces the same value as fetching using doc values.- Throws:
IOException
-
dedupAfterFetch
protected boolean dedupAfterFetch()A few field types (e.g. keyword fields) don't allow duplicate values, so in those cases we need to de-dup our expected values. Field types where this is the case should overwrite this. The default is to not de-duplicate though. -
supportsSearchLookup
protected boolean supportsSearchLookup()- Returns:
- whether or not this field type supports access to its values from a SearchLookup
-
testIndexTimeFieldData
Checks that field data from this field produces the same values for query-time scripts and for index-time scripts- Throws:
IOException
-
supportsStoredFields
protected boolean supportsStoredFields() -
minimalStoreMapping
- Throws:
IOException
-
testIndexTimeStoredFieldsAccess
Checks that loading stored fields for this field produces the same set of values for query time scripts and index time scripts- Throws:
IOException
-
testNullInput
- Throws:
Exception
-
allowsNullValues
protected boolean allowsNullValues() -
testMinimalIsInvalidInRoutingPath
- Throws:
IOException
-
minimalIsInvalidRoutingPathErrorMessage
-
syntheticSourceSupport
protected abstract MapperTestCase.SyntheticSourceSupport syntheticSourceSupport(boolean ignoreMalformed) -
testSyntheticSource
- Throws:
IOException
-
testSyntheticSourceIgnoreMalformedExamples
- Throws:
IOException
-
supportsEmptyInputArray
protected boolean supportsEmptyInputArray() -
testSyntheticSourceMany
- Throws:
IOException
-
testNoSyntheticSourceForScript
- Throws:
IOException
-
testSyntheticSourceInObject
- Throws:
IOException
-
testSyntheticEmptyList
- Throws:
IOException
-
testSyntheticEmptyListNoDocValuesLoader
- Throws:
IOException
-
testEmptyDocumentNoDocValueLoader
- Throws:
IOException
-
addsValueWhenNotSupplied
protected boolean addsValueWhenNotSupplied() -
testSyntheticSourceInvalid
- Throws:
IOException
-
compileScript
Description copied from class:MapperServiceTestCase
This is the injection point for tests that require mock scripts. Test cases should override this to return the mock script factory of their choice.- Overrides:
compileScript
in classMapperServiceTestCase
-
ingestScriptSupport
-