35
35
import org .elasticsearch .index .mapper .MappedFieldType ;
36
36
import org .elasticsearch .index .mapper .MapperService ;
37
37
import org .elasticsearch .index .mapper .MappingLookup ;
38
+ import org .elasticsearch .index .mapper .NestedPathFieldMapper ;
38
39
import org .elasticsearch .index .mapper .ParsedDocument ;
39
40
import org .elasticsearch .index .mapper .SourceFieldMapper ;
40
41
import org .elasticsearch .index .mapper .SourceToParse ;
@@ -185,6 +186,11 @@ private static boolean isValidField(MappedFieldType fieldType) {
185
186
if (fieldType .isIndexed () == false ) {
186
187
return false ;
187
188
}
189
+ // and must not be the nested path field
190
+ if (fieldType .name ().equals (NestedPathFieldMapper .NAME )) {
191
+ return false ;
192
+ }
193
+
188
194
return true ;
189
195
}
190
196
@@ -291,7 +297,13 @@ private static Fields generateTermVectors(
291
297
MemoryIndex index = new MemoryIndex (withOffsets );
292
298
for (Map .Entry <String , Collection <Object >> entry : values .entrySet ()) {
293
299
String field = entry .getKey ();
294
- Analyzer analyzer = getAnalyzerAtField (indexShard , field , perFieldAnalyzer );
300
+ final Analyzer analyzer ;
301
+ try {
302
+ analyzer = getAnalyzerAtField (indexShard , field , perFieldAnalyzer );
303
+ } catch (IllegalArgumentException e ) {
304
+ // failed to get the analyzer for the given field, it could be a metadata field
305
+ continue ;
306
+ }
295
307
if (entry .getValue () instanceof List ) {
296
308
for (Object text : entry .getValue ()) {
297
309
index .addField (field , text .toString (), analyzer );
@@ -310,25 +322,26 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect
310
322
MappingLookup mappingLookup = indexShard .mapperService ().mappingLookup ();
311
323
ParsedDocument parsedDocument = documentParser .parseDocument (source , mappingLookup );
312
324
// select the right fields and generate term vectors
313
- LuceneDocument doc = parsedDocument .rootDoc ();
314
- Set <String > seenFields = new HashSet <>();
315
- Collection <DocumentField > documentFields = new HashSet <>();
316
- for (IndexableField field : doc .getFields ()) {
317
- MappedFieldType fieldType = indexShard .mapperService ().fieldType (field .name ());
318
- if (isValidField (fieldType ) == false ) {
319
- continue ;
320
- }
321
- if (request .selectedFields () != null && request .selectedFields ().contains (field .name ()) == false ) {
322
- continue ;
323
- }
324
- if (seenFields .contains (field .name ())) {
325
- continue ;
326
- } else {
327
- seenFields .add (field .name ());
325
+ final Set <String > seenFields = new HashSet <>();
326
+ final Collection <DocumentField > documentFields = new HashSet <>();
327
+ for (LuceneDocument doc : parsedDocument .docs ()) {
328
+ for (IndexableField field : doc .getFields ()) {
329
+ MappedFieldType fieldType = indexShard .mapperService ().fieldType (field .name ());
330
+ if (isValidField (fieldType ) == false ) {
331
+ continue ;
332
+ }
333
+ if (request .selectedFields () != null && request .selectedFields ().contains (field .name ()) == false ) {
334
+ continue ;
335
+ }
336
+ if (seenFields .contains (field .name ())) {
337
+ continue ;
338
+ } else {
339
+ seenFields .add (field .name ());
340
+ }
341
+ @ SuppressWarnings ("unchecked" )
342
+ List <Object > values = (List ) getValues (doc .getFields (field .name ()));
343
+ documentFields .add (new DocumentField (field .name (), values ));
328
344
}
329
- @ SuppressWarnings ("unchecked" )
330
- List <Object > values = (List ) getValues (doc .getFields (field .name ()));
331
- documentFields .add (new DocumentField (field .name (), values ));
332
345
}
333
346
return generateTermVectors (
334
347
indexShard ,
0 commit comments