2626import org .springframework .data .elasticsearch .annotations .IndexOptions ;
2727import org .springframework .data .elasticsearch .annotations .IndexPrefixes ;
2828import org .springframework .data .elasticsearch .annotations .InnerField ;
29+ import org .springframework .data .elasticsearch .annotations .NullValueType ;
2930import org .springframework .data .elasticsearch .annotations .Similarity ;
3031import org .springframework .data .elasticsearch .annotations .TermVector ;
3132import org .springframework .util .Assert ;
@@ -44,8 +45,10 @@ public final class MappingParameters {
4445
4546 static final String FIELD_PARAM_COERCE = "coerce" ;
4647 static final String FIELD_PARAM_COPY_TO = "copy_to" ;
47- static final String FIELD_PARAM_DOC_VALUES = "doc_values" ;
4848 static final String FIELD_PARAM_DATA = "fielddata" ;
49+ static final String FIELD_PARAM_DOC_VALUES = "doc_values" ;
50+ static final String FIELD_PARAM_EAGER_GLOBAL_ORDINALS = "eager_global_ordinals" ;
51+ static final String FIELD_PARAM_ENABLED = "enabled" ;
4952 static final String FIELD_PARAM_FORMAT = "format" ;
5053 static final String FIELD_PARAM_IGNORE_ABOVE = "ignore_above" ;
5154 static final String FIELD_PARAM_IGNORE_MALFORMED = "ignore_malformed" ;
@@ -56,44 +59,47 @@ public final class MappingParameters {
5659 static final String FIELD_PARAM_INDEX_PREFIXES_MIN_CHARS = "min_chars" ;
5760 static final String FIELD_PARAM_INDEX_PREFIXES_MAX_CHARS = "max_chars" ;
5861 static final String FIELD_PARAM_INDEX_ANALYZER = "analyzer" ;
62+ static final String FIELD_PARAM_MAX_SHINGLE_SIZE = "max_shingle_size" ;
5963 static final String FIELD_PARAM_NORMALIZER = "normalizer" ;
6064 static final String FIELD_PARAM_NORMS = "norms" ;
6165 static final String FIELD_PARAM_NULL_VALUE = "null_value" ;
62- static final String FIELD_PARAMETER_NAME_POSITION_INCREMENT_GAP = "position_increment_gap" ;
66+ static final String FIELD_PARAM_POSITION_INCREMENT_GAP = "position_increment_gap" ;
67+ static final String FIELD_PARAM_POSITIVE_SCORE_IMPACT = "positive_score_impact" ;
6368 static final String FIELD_PARAM_SCALING_FACTOR = "scaling_factor" ;
6469 static final String FIELD_PARAM_SEARCH_ANALYZER = "search_analyzer" ;
6570 static final String FIELD_PARAM_STORE = "store" ;
6671 static final String FIELD_PARAM_SIMILARITY = "similarity" ;
6772 static final String FIELD_PARAM_TERM_VECTOR = "term_vector" ;
6873 static final String FIELD_PARAM_TYPE = "type" ;
69- static final String FIELD_PARAM_MAX_SHINGLE_SIZE = "max_shingle_size" ;
70- static final String FIELD_PARAM_POSITIVE_SCORE_IMPACT = "positive_score_impact" ;
7174
72- private boolean index = true ;
73- private boolean store = false ;
74- private boolean fielddata = false ;
75- private FieldType type = null ;
76- private DateFormat dateFormat = null ;
77- private String datePattern = null ;
78- private String analyzer = null ;
79- private String searchAnalyzer = null ;
80- private String normalizer = null ;
81- private String [] copyTo = null ;
82- private Integer ignoreAbove = null ;
83- private boolean coerce = true ;
84- private boolean docValues = true ;
85- private boolean ignoreMalformed = false ;
86- private IndexOptions indexOptions = null ;
87- boolean indexPhrases = false ;
88- private IndexPrefixes indexPrefixes = null ;
89- private boolean norms = true ;
90- private String nullValue = null ;
91- private Integer positionIncrementGap = null ;
92- private Similarity similarity = Similarity .Default ;
93- private TermVector termVector = TermVector .none ;
94- private double scalingFactor = 1.0 ;
95- @ Nullable private Integer maxShingleSize ;
96- private boolean positiveScoreImpact = true ;
75+ private final String analyzer ;
76+ private final boolean coerce ;
77+ @ Nullable private final String [] copyTo ;
78+ private final String datePattern ;
79+ private final boolean docValues ;
80+ private final boolean eagerGlobalOrdinals ;
81+ private final boolean enabled ;
82+ private final boolean fielddata ;
83+ private final DateFormat format ;
84+ @ Nullable private final Integer ignoreAbove ;
85+ private final boolean ignoreMalformed ;
86+ private final boolean index ;
87+ private final IndexOptions indexOptions ;
88+ private final boolean indexPhrases ;
89+ @ Nullable private final IndexPrefixes indexPrefixes ;
90+ private final String normalizer ;
91+ private final boolean norms ;
92+ @ Nullable private final Integer maxShingleSize ;
93+ private final String nullValue ;
94+ private final NullValueType nullValueType ;
95+ private final Integer positionIncrementGap ;
96+ private final boolean positiveScoreImpact ;
97+ private final String searchAnalyzer ;
98+ private final double scalingFactor ;
99+ private final Similarity similarity ;
100+ private final boolean store ;
101+ private final TermVector termVector ;
102+ private final FieldType type ;
97103
98104 /**
99105 * extracts the mapping parameters from the relevant annotations.
@@ -119,7 +125,7 @@ private MappingParameters(Field field) {
119125 store = field .store ();
120126 fielddata = field .fielddata ();
121127 type = field .type ();
122- dateFormat = field .format ();
128+ format = field .format ();
123129 datePattern = field .pattern ();
124130 analyzer = field .analyzer ();
125131 searchAnalyzer = field .searchAnalyzer ();
@@ -133,11 +139,10 @@ private MappingParameters(Field field) {
133139 ignoreMalformed = field .ignoreMalformed ();
134140 indexOptions = field .indexOptions ();
135141 indexPhrases = field .indexPhrases ();
136- if (field .indexPrefixes ().length > 0 ) {
137- indexPrefixes = field .indexPrefixes ()[0 ];
138- }
142+ indexPrefixes = field .indexPrefixes ().length > 0 ? field .indexPrefixes ()[0 ] : null ;
139143 norms = field .norms ();
140144 nullValue = field .nullValue ();
145+ nullValueType = field .nullValueType ();
141146 positionIncrementGap = field .positionIncrementGap ();
142147 similarity = field .similarity ();
143148 termVector = field .termVector ();
@@ -148,18 +153,22 @@ private MappingParameters(Field field) {
148153 || (maxShingleSize >= 2 && maxShingleSize <= 4 ), //
149154 "maxShingleSize must be in inclusive range from 2 to 4 for field type search_as_you_type" );
150155 positiveScoreImpact = field .positiveScoreImpact ();
156+ Assert .isTrue (field .enabled () || type == FieldType .Object , "enabled false is only allowed for field type object" );
157+ enabled = field .enabled ();
158+ eagerGlobalOrdinals = field .eagerGlobalOrdinals ();
151159 }
152160
153161 private MappingParameters (InnerField field ) {
154162 index = field .index ();
155163 store = field .store ();
156164 fielddata = field .fielddata ();
157165 type = field .type ();
158- dateFormat = field .format ();
166+ format = field .format ();
159167 datePattern = field .pattern ();
160168 analyzer = field .analyzer ();
161169 searchAnalyzer = field .searchAnalyzer ();
162170 normalizer = field .normalizer ();
171+ copyTo = null ;
163172 ignoreAbove = field .ignoreAbove () >= 0 ? field .ignoreAbove () : null ;
164173 coerce = field .coerce ();
165174 docValues = field .docValues ();
@@ -168,11 +177,10 @@ private MappingParameters(InnerField field) {
168177 ignoreMalformed = field .ignoreMalformed ();
169178 indexOptions = field .indexOptions ();
170179 indexPhrases = field .indexPhrases ();
171- if (field .indexPrefixes ().length > 0 ) {
172- indexPrefixes = field .indexPrefixes ()[0 ];
173- }
180+ indexPrefixes = field .indexPrefixes ().length > 0 ? field .indexPrefixes ()[0 ] : null ;
174181 norms = field .norms ();
175182 nullValue = field .nullValue ();
183+ nullValueType = field .nullValueType ();
176184 positionIncrementGap = field .positionIncrementGap ();
177185 similarity = field .similarity ();
178186 termVector = field .termVector ();
@@ -183,6 +191,8 @@ private MappingParameters(InnerField field) {
183191 || (maxShingleSize >= 2 && maxShingleSize <= 4 ), //
184192 "maxShingleSize must be in inclusive range from 2 to 4 for field type search_as_you_type" );
185193 positiveScoreImpact = field .positiveScoreImpact ();
194+ enabled = true ;
195+ eagerGlobalOrdinals = field .eagerGlobalOrdinals ();
186196 }
187197
188198 public boolean isStore () {
@@ -204,8 +214,8 @@ public void writeTypeAndParametersTo(XContentBuilder builder) throws IOException
204214
205215 if (type != FieldType .Auto ) {
206216 builder .field (FIELD_PARAM_TYPE , type .name ().toLowerCase ());
207- if (type == FieldType .Date && dateFormat != DateFormat .none ) {
208- builder .field (FIELD_PARAM_FORMAT , dateFormat == DateFormat .custom ? datePattern : dateFormat .toString ());
217+ if (type == FieldType .Date && format != DateFormat .none ) {
218+ builder .field (FIELD_PARAM_FORMAT , format == DateFormat .custom ? datePattern : format .toString ());
209219 }
210220 }
211221
@@ -270,11 +280,27 @@ public void writeTypeAndParametersTo(XContentBuilder builder) throws IOException
270280 }
271281
272282 if (!StringUtils .isEmpty (nullValue )) {
273- builder .field (FIELD_PARAM_NULL_VALUE , nullValue );
283+ Object value ;
284+ switch (nullValueType ) {
285+ case Integer :
286+ value = Integer .valueOf (nullValue );
287+ break ;
288+ case Long :
289+ value = Long .valueOf (nullValue );
290+ break ;
291+ case Double :
292+ value = Double .valueOf (nullValue );
293+ break ;
294+ case String :
295+ default :
296+ value = nullValue ;
297+ break ;
298+ }
299+ builder .field (FIELD_PARAM_NULL_VALUE , value );
274300 }
275301
276302 if (positionIncrementGap != null && positionIncrementGap >= 0 ) {
277- builder .field (FIELD_PARAMETER_NAME_POSITION_INCREMENT_GAP , positionIncrementGap );
303+ builder .field (FIELD_PARAM_POSITION_INCREMENT_GAP , positionIncrementGap );
278304 }
279305
280306 if (similarity != Similarity .Default ) {
@@ -296,5 +322,13 @@ public void writeTypeAndParametersTo(XContentBuilder builder) throws IOException
296322 if (!positiveScoreImpact ) {
297323 builder .field (FIELD_PARAM_POSITIVE_SCORE_IMPACT , positiveScoreImpact );
298324 }
325+
326+ if (!enabled ) {
327+ builder .field (FIELD_PARAM_ENABLED , enabled );
328+ }
329+
330+ if (eagerGlobalOrdinals ) {
331+ builder .field (FIELD_PARAM_EAGER_GLOBAL_ORDINALS , eagerGlobalOrdinals );
332+ }
299333 }
300334}
0 commit comments