Skip to content

Commit be07bd7

Browse files
committed
Add match_only_text matcher
1 parent 381b84e commit be07bd7

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

test/framework/src/main/java/org/elasticsearch/datageneration/datasource/DefaultMappingParametersHandler.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,6 @@ private Supplier<Map<String, Object>> wildcardMapping(boolean hasParent, DataSou
263263
}
264264

265265
private Map<String, Object> stringSubField(FieldType parent, DataSourceRequest.LeafMappingParametersGenerator request) {
266-
/**
267-
* text -> keyword, wildcard
268-
* match_only_text -> keyword, wildcard
269-
* patterned_text -> keyword, wildcard
270-
* keyword -> text, match_only_text, patterned_tet, wildcard
271-
* wildcard -> keyword, text, match_only_text, patterned_text
272-
*
273-
*/
274266
var subFields = new HashMap<FieldType, Supplier<Map<String, Object>>>();
275267
subFields.put(FieldType.KEYWORD, () -> {
276268
var mapping = keywordMapping(true, request).get();

test/framework/src/main/java/org/elasticsearch/datageneration/matchers/source/FieldSpecificMatcher.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static Map<String, FieldSpecificMatcher> matchers(
6262
put("geo_shape", new ExactMatcher("geo_shape", actualMappings, actualSettings, expectedMappings, expectedSettings));
6363
put("shape", new ExactMatcher("shape", actualMappings, actualSettings, expectedMappings, expectedSettings));
6464
put("geo_point", new GeoPointMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
65-
put("text", new TextMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
65+
put("text", new TextMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings, false));
66+
put("match_only_text", new TextMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings, true));
6667
put("ip", new IpMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
6768
put("constant_keyword", new ConstantKeywordMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
6869
put("wildcard", new WildcardMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings));
@@ -608,17 +609,20 @@ class TextMatcher implements FieldSpecificMatcher {
608609
private final Settings.Builder actualSettings;
609610
private final XContentBuilder expectedMappings;
610611
private final Settings.Builder expectedSettings;
612+
private final boolean isMatchOnlyText;
611613

612614
TextMatcher(
613615
XContentBuilder actualMappings,
614616
Settings.Builder actualSettings,
615617
XContentBuilder expectedMappings,
616-
Settings.Builder expectedSettings
618+
Settings.Builder expectedSettings,
619+
boolean isMatchOnlyText
617620
) {
618621
this.actualMappings = actualMappings;
619622
this.actualSettings = actualSettings;
620623
this.expectedMappings = expectedMappings;
621624
this.expectedSettings = expectedSettings;
625+
this.isMatchOnlyText = isMatchOnlyText;
622626
}
623627

624628
@Override
@@ -640,23 +644,24 @@ public MatchResult match(
640644
// In some cases synthetic source for text fields is synthesized using the keyword multi field.
641645
// So in this case it's appropriate to match it using keyword matching logic (mainly to cover `null_value`).
642646
var multiFields = (Map<String, Object>) getMappingParameter("fields", actualMapping, expectedMapping);
643-
if (multiFields != null) {
647+
if (multiFields != null && multiFields.containsKey("subfield_keyword")) {
644648
var keywordMatcher = new KeywordMatcher(actualMappings, actualSettings, expectedMappings, expectedSettings);
645649

646-
var keywordFieldMapping = (Map<String, Object>) multiFields.get("kwd");
650+
var keywordFieldMapping = (Map<String, Object>) multiFields.get("subfield_keyword");
647651
var keywordMatchResult = keywordMatcher.match(actual, expected, keywordFieldMapping, keywordFieldMapping);
648652
if (keywordMatchResult.isMatch()) {
649653
return MatchResult.match();
650654
}
651655
}
652656

657+
var typeName = isMatchOnlyText ? "match_only_text" : "text";
653658
return MatchResult.noMatch(
654659
formatErrorMessage(
655660
actualMappings,
656661
actualSettings,
657662
expectedMappings,
658663
expectedSettings,
659-
"Values of type [text] don't match, " + prettyPrintCollections(actual, expected)
664+
"Values of type [" + typeName + "] don't match, " + prettyPrintCollections(actual, expected)
660665
)
661666
);
662667
}

0 commit comments

Comments
 (0)