@@ -104,8 +104,15 @@ public static class Builder extends FieldMapper.Builder {
104
104
105
105
private final TextParams .Analyzers analyzers ;
106
106
private final boolean withinMultiField ;
107
+ private final boolean storedFieldInBinaryFormat ;
107
108
108
- public Builder (String name , IndexVersion indexCreatedVersion , IndexAnalyzers indexAnalyzers , boolean withinMultiField ) {
109
+ public Builder (
110
+ String name ,
111
+ IndexVersion indexCreatedVersion ,
112
+ IndexAnalyzers indexAnalyzers ,
113
+ boolean withinMultiField ,
114
+ boolean storedFieldInBinaryFormat
115
+ ) {
109
116
super (name );
110
117
this .indexCreatedVersion = indexCreatedVersion ;
111
118
this .analyzers = new TextParams .Analyzers (
@@ -115,6 +122,7 @@ public Builder(String name, IndexVersion indexCreatedVersion, IndexAnalyzers ind
115
122
indexCreatedVersion
116
123
);
117
124
this .withinMultiField = withinMultiField ;
125
+ this .storedFieldInBinaryFormat = storedFieldInBinaryFormat ;
118
126
}
119
127
120
128
@ Override
@@ -134,7 +142,8 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context) {
134
142
context .isSourceSynthetic (),
135
143
meta .getValue (),
136
144
withinMultiField ,
137
- multiFieldsBuilder .hasSyntheticSourceCompatibleKeywordField ()
145
+ multiFieldsBuilder .hasSyntheticSourceCompatibleKeywordField (),
146
+ storedFieldInBinaryFormat
138
147
);
139
148
return ft ;
140
149
}
@@ -154,8 +163,18 @@ public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
154
163
}
155
164
}
156
165
166
+ private static boolean isSyntheticSourceStoredFieldInBinaryFormat (IndexVersion indexCreatedVersion ) {
167
+ return indexCreatedVersion .onOrAfter (IndexVersions .MATCH_ONLY_TEXT_STORED_AS_BYTES_BACKPORT_8_X );
168
+ }
169
+
157
170
public static final TypeParser PARSER = new TypeParser (
158
- (n , c ) -> new Builder (n , c .indexVersionCreated (), c .getIndexAnalyzers (), c .isWithinMultiField ())
171
+ (n , c ) -> new Builder (
172
+ n ,
173
+ c .indexVersionCreated (),
174
+ c .getIndexAnalyzers (),
175
+ c .isWithinMultiField (),
176
+ isSyntheticSourceStoredFieldInBinaryFormat (c .indexVersionCreated ())
177
+ )
159
178
);
160
179
161
180
public static class MatchOnlyTextFieldType extends StringFieldType {
@@ -166,6 +185,7 @@ public static class MatchOnlyTextFieldType extends StringFieldType {
166
185
167
186
private final boolean withinMultiField ;
168
187
private final boolean hasCompatibleMultiFields ;
188
+ private final boolean storedFieldInBinaryFormat ;
169
189
170
190
public MatchOnlyTextFieldType (
171
191
String name ,
@@ -174,14 +194,16 @@ public MatchOnlyTextFieldType(
174
194
boolean isSyntheticSource ,
175
195
Map <String , String > meta ,
176
196
boolean withinMultiField ,
177
- boolean hasCompatibleMultiFields
197
+ boolean hasCompatibleMultiFields ,
198
+ boolean storedFieldInBinaryFormat
178
199
) {
179
200
super (name , true , false , false , tsi , meta );
180
201
this .indexAnalyzer = Objects .requireNonNull (indexAnalyzer );
181
202
this .textFieldType = new TextFieldType (name , isSyntheticSource );
182
203
this .originalName = isSyntheticSource ? name () + "._original" : null ;
183
204
this .withinMultiField = withinMultiField ;
184
205
this .hasCompatibleMultiFields = hasCompatibleMultiFields ;
206
+ this .storedFieldInBinaryFormat = storedFieldInBinaryFormat ;
185
207
}
186
208
187
209
public MatchOnlyTextFieldType (String name ) {
@@ -192,6 +214,7 @@ public MatchOnlyTextFieldType(String name) {
192
214
false ,
193
215
Collections .emptyMap (),
194
216
false ,
217
+ false ,
195
218
false
196
219
);
197
220
}
@@ -450,7 +473,11 @@ protected BytesRef toBytesRef(Object v) {
450
473
@ Override
451
474
public BlockLoader blockLoader (BlockLoaderContext blContext ) {
452
475
if (textFieldType .isSyntheticSource ()) {
453
- return new BytesFromMixedStringsBytesRefBlockLoader (storedFieldNameForSyntheticSource ());
476
+ if (storedFieldInBinaryFormat ) {
477
+ return new BlockStoredFieldsReader .BytesFromBytesRefsBlockLoader (storedFieldNameForSyntheticSource ());
478
+ } else {
479
+ return new BytesFromMixedStringsBytesRefBlockLoader (storedFieldNameForSyntheticSource ());
480
+ }
454
481
}
455
482
SourceValueFetcher fetcher = SourceValueFetcher .toString (blContext .sourcePaths (name ()));
456
483
// MatchOnlyText never has norms, so we have to use the field names field
@@ -501,6 +528,7 @@ private String storedFieldNameForSyntheticSource() {
501
528
private final boolean storeSource ;
502
529
private final FieldType fieldType ;
503
530
private final boolean withinMultiField ;
531
+ private final boolean storedFieldInBinaryFormat ;
504
532
505
533
private MatchOnlyTextFieldMapper (
506
534
String simpleName ,
@@ -520,6 +548,7 @@ private MatchOnlyTextFieldMapper(
520
548
this .positionIncrementGap = builder .analyzers .positionIncrementGap .getValue ();
521
549
this .storeSource = storeSource ;
522
550
this .withinMultiField = builder .withinMultiField ;
551
+ this .storedFieldInBinaryFormat = builder .storedFieldInBinaryFormat ;
523
552
}
524
553
525
554
@ Override
@@ -529,7 +558,7 @@ public Map<String, NamedAnalyzer> indexAnalyzers() {
529
558
530
559
@ Override
531
560
public FieldMapper .Builder getMergeBuilder () {
532
- return new Builder (leafName (), indexCreatedVersion , indexAnalyzers , withinMultiField ).init (this );
561
+ return new Builder (leafName (), indexCreatedVersion , indexAnalyzers , withinMultiField , storedFieldInBinaryFormat ).init (this );
533
562
}
534
563
535
564
@ Override
@@ -546,8 +575,12 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
546
575
context .addToFieldNames (fieldType ().name ());
547
576
548
577
if (storeSource ) {
549
- final var bytesRef = new BytesRef (utfBytes .bytes (), utfBytes .offset (), utfBytes .length ());
550
- context .doc ().add (new StoredField (fieldType ().storedFieldNameForSyntheticSource (), bytesRef ));
578
+ if (storedFieldInBinaryFormat ) {
579
+ final var bytesRef = new BytesRef (utfBytes .bytes (), utfBytes .offset (), utfBytes .length ());
580
+ context .doc ().add (new StoredField (fieldType ().storedFieldNameForSyntheticSource (), bytesRef ));
581
+ } else {
582
+ context .doc ().add (new StoredField (fieldType ().storedFieldNameForSyntheticSource (), value .string ()));
583
+ }
551
584
}
552
585
}
553
586
0 commit comments