45
45
import org .elasticsearch .index .mapper .KeywordFieldMapper ;
46
46
import org .elasticsearch .index .mapper .MappedFieldType ;
47
47
import org .elasticsearch .index .mapper .MapperService ;
48
+ import org .elasticsearch .index .mapper .ObjectMapper ;
48
49
import org .elasticsearch .index .mapper .ParseContext ;
49
50
import org .elasticsearch .index .mapper .ParsedDocument ;
50
51
import org .elasticsearch .index .mapper .SourceFieldMapper ;
@@ -160,7 +161,7 @@ private static void handleFieldWildcards(IndexShard indexShard, TermVectorsReque
160
161
request .selectedFields (fieldNames .toArray (Strings .EMPTY_ARRAY ));
161
162
}
162
163
163
- private static boolean isValidField (MappedFieldType fieldType ) {
164
+ private static boolean isValidField (MappedFieldType fieldType , IndexShard indexShard ) {
164
165
// must be a string
165
166
if (fieldType instanceof StringFieldType == false ) {
166
167
return false ;
@@ -169,6 +170,16 @@ private static boolean isValidField(MappedFieldType fieldType) {
169
170
if (fieldType .indexOptions () == IndexOptions .NONE ) {
170
171
return false ;
171
172
}
173
+ // and must not be under nested field
174
+ int dotIndex = fieldType .name ().indexOf ('.' );
175
+ while (dotIndex > -1 ) {
176
+ String parentField = fieldType .name ().substring (0 , dotIndex );
177
+ ObjectMapper mapper = indexShard .mapperService ().getObjectMapper (parentField );
178
+ if (mapper != null && mapper .nested ().isNested ()) {
179
+ return false ;
180
+ }
181
+ dotIndex = fieldType .name ().indexOf ('.' , dotIndex + 1 );
182
+ }
172
183
return true ;
173
184
}
174
185
@@ -177,7 +188,7 @@ private static Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetR
177
188
Set <String > validFields = new HashSet <>();
178
189
for (String field : selectedFields ) {
179
190
MappedFieldType fieldType = indexShard .mapperService ().fullName (field );
180
- if (! isValidField (fieldType ) ) {
191
+ if (isValidField (fieldType , indexShard ) == false ) {
181
192
continue ;
182
193
}
183
194
// already retrieved, only if the analyzer hasn't been overridden at the field
@@ -284,7 +295,7 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect
284
295
Collection <DocumentField > documentFields = new HashSet <>();
285
296
for (IndexableField field : doc .getFields ()) {
286
297
MappedFieldType fieldType = indexShard .mapperService ().fullName (field .name ());
287
- if (! isValidField (fieldType ) ) {
298
+ if (isValidField (fieldType , indexShard ) == false ) {
288
299
continue ;
289
300
}
290
301
if (request .selectedFields () != null && !request .selectedFields ().contains (field .name ())) {
0 commit comments