23
23
import org .elasticsearch .common .Strings ;
24
24
import org .elasticsearch .common .collect .ImmutableMap ;
25
25
import org .elasticsearch .common .joda .FormatDateTimeFormatter ;
26
- import org .elasticsearch .common .joda .Joda ;
27
26
import org .elasticsearch .common .util .concurrent .ThreadSafe ;
28
27
import org .elasticsearch .common .xcontent .XContentBuilder ;
29
28
import org .elasticsearch .common .xcontent .XContentParser ;
@@ -53,11 +52,6 @@ public static class Defaults {
53
52
public static final boolean ENABLED = true ;
54
53
public static final boolean DYNAMIC = true ;
55
54
public static final ContentPath .Type PATH_TYPE = ContentPath .Type .FULL ;
56
- public static final FormatDateTimeFormatter [] DATE_TIME_FORMATTERS =
57
- new FormatDateTimeFormatter []{
58
- DateFieldMapper .Defaults .DATE_TIME_FORMATTER ,
59
- Joda .forPattern ("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd" )
60
- };
61
55
}
62
56
63
57
public static class Builder <T extends Builder , Y extends ObjectMapper > extends XContentMapper .Builder <T , Y > {
@@ -68,8 +62,6 @@ public static class Builder<T extends Builder, Y extends ObjectMapper> extends X
68
62
69
63
protected ContentPath .Type pathType = Defaults .PATH_TYPE ;
70
64
71
- protected List <FormatDateTimeFormatter > dateTimeFormatters = newArrayList ();
72
-
73
65
protected Boolean includeInAll ;
74
66
75
67
protected final List <XContentMapper .Builder > mappersBuilders = newArrayList ();
@@ -94,45 +86,17 @@ public T pathType(ContentPath.Type pathType) {
94
86
return builder ;
95
87
}
96
88
97
- public T noDateTimeFormatter () {
98
- this .dateTimeFormatters = null ;
99
- return builder ;
100
- }
101
-
102
89
public T includeInAll (boolean includeInAll ) {
103
90
this .includeInAll = includeInAll ;
104
91
return builder ;
105
92
}
106
93
107
- public T dateTimeFormatter (Iterable <FormatDateTimeFormatter > dateTimeFormatters ) {
108
- for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters ) {
109
- this .dateTimeFormatters .add (dateTimeFormatter );
110
- }
111
- return builder ;
112
- }
113
-
114
- public T dateTimeFormatter (FormatDateTimeFormatter [] dateTimeFormatters ) {
115
- this .dateTimeFormatters .addAll (newArrayList (dateTimeFormatters ));
116
- return builder ;
117
- }
118
-
119
- public T dateTimeFormatter (FormatDateTimeFormatter dateTimeFormatter ) {
120
- this .dateTimeFormatters .add (dateTimeFormatter );
121
- return builder ;
122
- }
123
-
124
94
public T add (XContentMapper .Builder builder ) {
125
95
mappersBuilders .add (builder );
126
96
return this .builder ;
127
97
}
128
98
129
99
@ Override public Y build (BuilderContext context ) {
130
- if (dateTimeFormatters == null ) {
131
- dateTimeFormatters = newArrayList ();
132
- } else if (dateTimeFormatters .isEmpty ()) {
133
- // add the default one
134
- dateTimeFormatters .addAll (newArrayList (Defaults .DATE_TIME_FORMATTERS ));
135
- }
136
100
ContentPath .Type origPathType = context .path ().pathType ();
137
101
context .path ().pathType (pathType );
138
102
context .path ().add (name );
@@ -142,8 +106,7 @@ public T add(XContentMapper.Builder builder) {
142
106
XContentMapper mapper = builder .build (context );
143
107
mappers .put (mapper .name (), mapper );
144
108
}
145
- ObjectMapper objectMapper = createMapper (name , enabled , dynamic , pathType ,
146
- dateTimeFormatters .toArray (new FormatDateTimeFormatter [dateTimeFormatters .size ()]), mappers );
109
+ ObjectMapper objectMapper = createMapper (name , enabled , dynamic , pathType , mappers );
147
110
148
111
context .path ().pathType (origPathType );
149
112
context .path ().remove ();
@@ -153,9 +116,8 @@ public T add(XContentMapper.Builder builder) {
153
116
return (Y ) objectMapper ;
154
117
}
155
118
156
- protected ObjectMapper createMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType ,
157
- FormatDateTimeFormatter [] dateTimeFormatters , Map <String , XContentMapper > mappers ) {
158
- return new ObjectMapper (name , enabled , dynamic , pathType , dateTimeFormatters , mappers );
119
+ protected ObjectMapper createMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType , Map <String , XContentMapper > mappers ) {
120
+ return new ObjectMapper (name , enabled , dynamic , pathType , mappers );
159
121
}
160
122
}
161
123
@@ -175,22 +137,6 @@ public static class TypeParser implements XContentMapper.TypeParser {
175
137
if (!type .equals ("object" )) {
176
138
throw new MapperParsingException ("Trying to parse an object but has a different type [" + type + "] for [" + name + "]" );
177
139
}
178
- } else if (fieldName .equals ("date_formats" )) {
179
- List <FormatDateTimeFormatter > dateTimeFormatters = newArrayList ();
180
- if (fieldNode instanceof List ) {
181
- for (Object node1 : (List ) fieldNode ) {
182
- dateTimeFormatters .add (parseDateTimeFormatter (fieldName , node1 ));
183
- }
184
- } else if ("none" .equals (fieldNode .toString ())) {
185
- dateTimeFormatters = null ;
186
- } else {
187
- dateTimeFormatters .add (parseDateTimeFormatter (fieldName , fieldNode ));
188
- }
189
- if (dateTimeFormatters == null ) {
190
- builder .noDateTimeFormatter ();
191
- } else {
192
- builder .dateTimeFormatter (dateTimeFormatters );
193
- }
194
140
} else if (fieldName .equals ("enabled" )) {
195
141
builder .enabled (nodeBooleanValue (fieldNode ));
196
142
} else if (fieldName .equals ("path" )) {
@@ -251,8 +197,6 @@ protected void processField(Builder builder, String fieldName, Object fieldNode)
251
197
252
198
private final ContentPath .Type pathType ;
253
199
254
- private final FormatDateTimeFormatter [] dateTimeFormatters ;
255
-
256
200
private Boolean includeInAll ;
257
201
258
202
private volatile ImmutableMap <String , XContentMapper > mappers = ImmutableMap .of ();
@@ -263,22 +207,16 @@ protected ObjectMapper(String name) {
263
207
this (name , Defaults .ENABLED , Defaults .DYNAMIC , Defaults .PATH_TYPE );
264
208
}
265
209
266
- protected ObjectMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType ) {
267
- this (name , enabled , dynamic , pathType , Defaults .DATE_TIME_FORMATTERS );
268
- }
269
210
270
- protected ObjectMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType ,
271
- FormatDateTimeFormatter [] dateTimeFormatters ) {
272
- this (name , enabled , dynamic , pathType , dateTimeFormatters , null );
211
+ protected ObjectMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType ) {
212
+ this (name , enabled , dynamic , pathType , null );
273
213
}
274
214
275
- ObjectMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType ,
276
- FormatDateTimeFormatter [] dateTimeFormatters , Map <String , XContentMapper > mappers ) {
215
+ ObjectMapper (String name , boolean enabled , boolean dynamic , ContentPath .Type pathType , Map <String , XContentMapper > mappers ) {
277
216
this .name = name ;
278
217
this .enabled = enabled ;
279
218
this .dynamic = dynamic ;
280
219
this .pathType = pathType ;
281
- this .dateTimeFormatters = dateTimeFormatters ;
282
220
if (mappers != null ) {
283
221
this .mappers = copyOf (mappers );
284
222
}
@@ -385,8 +323,7 @@ private void serializeObject(ParseContext context, String currentFieldName) thro
385
323
BuilderContext builderContext = new BuilderContext (context .path ());
386
324
XContentMapper .Builder builder = context .root ().findTemplateBuilder (context , currentFieldName , "object" );
387
325
if (builder == null ) {
388
- builder = XContentMapperBuilders .object (currentFieldName ).enabled (true )
389
- .dynamic (dynamic ).pathType (pathType ).dateTimeFormatter (dateTimeFormatters );
326
+ builder = XContentMapperBuilders .object (currentFieldName ).enabled (true ).dynamic (dynamic ).pathType (pathType );
390
327
}
391
328
objectMapper = builder .build (builderContext );
392
329
putMapper (objectMapper );
@@ -452,7 +389,7 @@ private void serializeValue(final ParseContext context, String currentFieldName,
452
389
boolean isDate = false ;
453
390
// a safe check since "1" gets parsed as well
454
391
if (text .contains (":" ) || text .contains ("-" ) || text .contains ("/" )) {
455
- for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters ) {
392
+ for (FormatDateTimeFormatter dateTimeFormatter : context . root (). dateTimeFormatters () ) {
456
393
try {
457
394
dateTimeFormatter .parser ().parseMillis (text );
458
395
XContentMapper .Builder builder = context .root ().findTemplateBuilder (context , currentFieldName , "date" );
@@ -605,14 +542,6 @@ public void toXContent(XContentBuilder builder, Params params, XContentMapper...
605
542
606
543
doXContent (builder , params );
607
544
608
- if (dateTimeFormatters .length > 0 ) {
609
- builder .startArray ("date_formats" );
610
- for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters ) {
611
- builder .value (dateTimeFormatter .format ());
612
- }
613
- builder .endArray ();
614
- }
615
-
616
545
// check internal mappers first (this is only relevant for root object)
617
546
for (XContentMapper mapper : mappers .values ()) {
618
547
if (mapper instanceof InternalMapper ) {
0 commit comments