Skip to content

Commit

Permalink
Explicitly say if stored fields aren't supported in MapperTestCase (#…
Browse files Browse the repository at this point in the history
…72474)

MapperTestCase has a check that if a field mapper supports stored fields,
those stored fields are available to index time scripts. Many of our mappers
do not support stored fields, and we try and catch this with an assumeFalse
so that those mappers do not run this test. However, this test is fragile - it
does not work for mappers created with an index version below 8.0, and it
misses mappers that always store their values, e.g. match_only_text.

This commit adds a new supportsStoredField method to MapperTestCase,
and overrides it for those mappers that do not support storing values. It
also adds a minimalStoredMapping method that defaults to the minimal
mapping plus a store parameter, which is overridden by match_only_text
because storing is not configurable and always available on this mapper.
  • Loading branch information
romseygeek authored Apr 30, 2021
1 parent 17717a0 commit 009f23e
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "match_only_text");
}

@Override
protected void minimalStoreMapping(XContentBuilder b) throws IOException {
// 'store' is always true
minimalMapping(b);
}

public void testDefaults() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
assertEquals(Strings.toString(fieldMapping(this::minimalMapping)), mapper.mappingSource().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ protected void assertSearchable(MappedFieldType fieldType) {
assertTrue(fieldType.isSearchable());
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected Collection<? extends Plugin> getPlugins() {
return List.of(new MapperExtrasPlugin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "rank_features");
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected void registerParameters(ParameterChecker checker) throws IOException {
checker.registerConflictCheck("positive_score_impact", b -> b.field("positive_score_impact", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ protected void metaMapping(XContentBuilder b) throws IOException {
b.field("max_input_length", 50);
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected void registerParameters(ParameterChecker checker) throws IOException {
checker.registerConflictCheck("analyzer", b -> b.field("analyzer", "standard"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "geo_shape");
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected Object getSampleValueForDocument() {
return "POINT (14.0 15.0)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "geo_shape").field("strategy", "recursive");
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected void registerParameters(ParameterChecker checker) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
m -> assertEquals(10, ((FlattenedFieldMapper)m).depthLimit()));
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testDefaults() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
ParsedDocument parsedDoc = mapper.parse(source(b -> b.startObject("field").field("key", "value").endObject()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,24 +643,24 @@ public final void testIndexTimeFieldData() throws IOException {
});
}

protected boolean supportsStoredFields() {
return true;
}

protected void minimalStoreMapping(XContentBuilder b) throws IOException {
minimalMapping(b);
b.field("store", true);
}

/**
* Checks that loading stored fields for this field produces the same set of values
* for query time scripts and index time scripts
*/
public final void testIndexTimeStoredFieldsAccess() throws IOException {

MapperService mapperService;
try {
mapperService = createMapperService(fieldMapping(b -> {
minimalMapping(b);
b.field("store", true);
}));
assertParseMinimalWarnings();
} catch (MapperParsingException e) {
assertParseMinimalWarnings();
assumeFalse("Field type does not support stored fields", true);
return;
}
assumeTrue("Field type does not support stored fields", supportsStoredFields());
MapperService mapperService = createMapperService(fieldMapping(this::minimalStoreMapping));
assertParseMinimalWarnings();

MappedFieldType fieldType = mapperService.fieldType("field");
SourceToParse source = source(this::writeField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ protected boolean supportsSearchLookup() {
return false;
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testParseValue() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
ParsedDocument doc = mapper.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ protected Object getSampleValueForQuery() {
return 50.0;
}

@Override
protected boolean supportsStoredFields() {
return false;
}

/**
* Test parsing field mapping and adding simple field
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ protected Collection<Plugin> getPlugins() {
return List.of(new ConstantKeywordMapperPlugin());
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testDefaults() throws Exception {
XContentBuilder mapping = fieldMapping(b -> b.field("type", "constant_keyword").field("value", "foo"));
DocumentMapper mapper = createDocumentMapper(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
// no configurable parameters
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testDefaults() throws Exception {
XContentBuilder mapping = fieldMapping(this::minimalMapping);
DocumentMapper mapper = createDocumentMapper(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ protected boolean supportsSearchLookup() {
return false;
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
protected void registerParameters(ParameterChecker checker) throws IOException {
checker.registerConflictCheck("doc_values", b -> b.field("doc_values", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
});
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testDefaultConfiguration() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
Mapper fieldMapper = mapper.mappers().getMapper(FIELD_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
fieldMapping(b -> b.field("type", "dense_vector").field("dims", 5)));
}

@Override
protected boolean supportsStoredFields() {
return false;
}

public void testDims() {
{
Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ protected Collection<? extends Plugin> getPlugins() {
return Collections.singleton(new Wildcard());
}

@Override
protected boolean supportsStoredFields() {
return false;
}

@Override
@Before
public void setUp() throws Exception {
Expand Down

0 comments on commit 009f23e

Please sign in to comment.