27
27
import org .elasticsearch .common .xcontent .XContentType ;
28
28
import org .slf4j .Logger ;
29
29
import org .slf4j .LoggerFactory ;
30
-
31
30
import org .springframework .core .io .ClassPathResource ;
32
31
import org .springframework .data .annotation .Transient ;
33
32
import org .springframework .data .elasticsearch .annotations .CompletionContext ;
@@ -364,7 +363,7 @@ private void addFieldMappingParameters(XContentBuilder builder, Object annotatio
364
363
searchAnalyzer = fieldAnnotation .searchAnalyzer ();
365
364
normalizer = fieldAnnotation .normalizer ();
366
365
copyTo = fieldAnnotation .copyTo ();
367
- ignoreAbove = fieldAnnotation .ignoreAbove ();
366
+ ignoreAbove = fieldAnnotation .ignoreAbove () >= 0 ? fieldAnnotation . ignoreAbove () : null ;
368
367
} else if (annotation instanceof InnerField ) {
369
368
// @InnerField
370
369
InnerField fieldAnnotation = (InnerField ) annotation ;
@@ -377,40 +376,48 @@ private void addFieldMappingParameters(XContentBuilder builder, Object annotatio
377
376
analyzer = fieldAnnotation .analyzer ();
378
377
searchAnalyzer = fieldAnnotation .searchAnalyzer ();
379
378
normalizer = fieldAnnotation .normalizer ();
380
- ignoreAbove = fieldAnnotation .ignoreAbove ();
379
+ ignoreAbove = fieldAnnotation .ignoreAbove () >= 0 ? fieldAnnotation . ignoreAbove () : null ;
381
380
} else {
382
381
throw new IllegalArgumentException ("annotation must be an instance of @Field or @InnerField" );
383
382
}
384
383
385
384
if (!nestedOrObjectField ) {
386
385
builder .field (FIELD_STORE , store );
387
386
}
387
+
388
388
if (fielddata ) {
389
389
builder .field (FIELD_DATA , fielddata );
390
390
}
391
+
391
392
if (type != FieldType .Auto ) {
392
393
builder .field (FIELD_TYPE , type .name ().toLowerCase ());
393
394
394
395
if (type == FieldType .Date && dateFormat != DateFormat .none ) {
395
396
builder .field (FIELD_FORMAT , dateFormat == DateFormat .custom ? datePattern : dateFormat .toString ());
396
397
}
397
398
}
399
+
398
400
if (!index ) {
399
401
builder .field (FIELD_INDEX , index );
400
402
}
403
+
401
404
if (!StringUtils .isEmpty (analyzer )) {
402
405
builder .field (FIELD_INDEX_ANALYZER , analyzer );
403
406
}
407
+
404
408
if (!StringUtils .isEmpty (searchAnalyzer )) {
405
409
builder .field (FIELD_SEARCH_ANALYZER , searchAnalyzer );
406
410
}
411
+
407
412
if (!StringUtils .isEmpty (normalizer )) {
408
413
builder .field (FIELD_NORMALIZER , normalizer );
409
414
}
415
+
410
416
if (copyTo != null && copyTo .length > 0 ) {
411
417
builder .field (FIELD_COPY_TO , copyTo );
412
418
}
413
- if (ignoreAbove != -1 ) {
419
+
420
+ if (ignoreAbove != null ) {
414
421
Assert .isTrue (ignoreAbove >= 0 , "ignore_above must be a positive value" );
415
422
builder .field (FIELD_IGNORE_ABOVE , ignoreAbove );
416
423
}
0 commit comments