Skip to content

Commit 165e02d

Browse files
committed
DATAES-639 - Polishing.
1 parent a9c3058 commit 165e02d

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/main/java/org/springframework/data/elasticsearch/annotations/Field.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package org.springframework.data.elasticsearch.annotations;
1717

18-
import org.springframework.core.annotation.AliasFor;
19-
2018
import java.lang.annotation.Documented;
2119
import java.lang.annotation.ElementType;
2220
import java.lang.annotation.Inherited;
2321
import java.lang.annotation.Retention;
2422
import java.lang.annotation.RetentionPolicy;
2523
import java.lang.annotation.Target;
2624

25+
import org.springframework.core.annotation.AliasFor;
26+
2727
/**
2828
* @author Rizwan Idrees
2929
* @author Mohsin Husen
@@ -42,14 +42,17 @@
4242

4343
/**
4444
* Alias for {@link #name}.
45+
*
4546
* @since 3.2
4647
*/
4748
@AliasFor("name")
4849
String value() default "";
4950

5051
/**
5152
* The <em>name</em> to be used to store the field inside the document.
52-
* <p>If not set, the name of the annotated property is used.
53+
* <p>√5
54+
* If not set, the name of the annotated property is used.
55+
*
5356
* @since 3.2
5457
*/
5558
@AliasFor("value")

src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.common.xcontent.XContentType;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
30-
3130
import org.springframework.core.io.ClassPathResource;
3231
import org.springframework.data.annotation.Transient;
3332
import org.springframework.data.elasticsearch.annotations.CompletionContext;
@@ -364,7 +363,7 @@ private void addFieldMappingParameters(XContentBuilder builder, Object annotatio
364363
searchAnalyzer = fieldAnnotation.searchAnalyzer();
365364
normalizer = fieldAnnotation.normalizer();
366365
copyTo = fieldAnnotation.copyTo();
367-
ignoreAbove = fieldAnnotation.ignoreAbove();
366+
ignoreAbove = fieldAnnotation.ignoreAbove() >= 0 ? fieldAnnotation.ignoreAbove() : null;
368367
} else if (annotation instanceof InnerField) {
369368
// @InnerField
370369
InnerField fieldAnnotation = (InnerField) annotation;
@@ -377,40 +376,48 @@ private void addFieldMappingParameters(XContentBuilder builder, Object annotatio
377376
analyzer = fieldAnnotation.analyzer();
378377
searchAnalyzer = fieldAnnotation.searchAnalyzer();
379378
normalizer = fieldAnnotation.normalizer();
380-
ignoreAbove = fieldAnnotation.ignoreAbove();
379+
ignoreAbove = fieldAnnotation.ignoreAbove() >= 0 ? fieldAnnotation.ignoreAbove() : null;
381380
} else {
382381
throw new IllegalArgumentException("annotation must be an instance of @Field or @InnerField");
383382
}
384383

385384
if (!nestedOrObjectField) {
386385
builder.field(FIELD_STORE, store);
387386
}
387+
388388
if (fielddata) {
389389
builder.field(FIELD_DATA, fielddata);
390390
}
391+
391392
if (type != FieldType.Auto) {
392393
builder.field(FIELD_TYPE, type.name().toLowerCase());
393394

394395
if (type == FieldType.Date && dateFormat != DateFormat.none) {
395396
builder.field(FIELD_FORMAT, dateFormat == DateFormat.custom ? datePattern : dateFormat.toString());
396397
}
397398
}
399+
398400
if (!index) {
399401
builder.field(FIELD_INDEX, index);
400402
}
403+
401404
if (!StringUtils.isEmpty(analyzer)) {
402405
builder.field(FIELD_INDEX_ANALYZER, analyzer);
403406
}
407+
404408
if (!StringUtils.isEmpty(searchAnalyzer)) {
405409
builder.field(FIELD_SEARCH_ANALYZER, searchAnalyzer);
406410
}
411+
407412
if (!StringUtils.isEmpty(normalizer)) {
408413
builder.field(FIELD_NORMALIZER, normalizer);
409414
}
415+
410416
if (copyTo != null && copyTo.length > 0) {
411417
builder.field(FIELD_COPY_TO, copyTo);
412418
}
413-
if (ignoreAbove != -1) {
419+
420+
if (ignoreAbove != null) {
414421
Assert.isTrue(ignoreAbove >= 0, "ignore_above must be a positive value");
415422
builder.field(FIELD_IGNORE_ABOVE, ignoreAbove);
416423
}

0 commit comments

Comments
 (0)