27
27
import org .elasticsearch .common .Strings ;
28
28
import org .elasticsearch .common .collect .ImmutableOpenMap ;
29
29
import org .elasticsearch .common .collect .Tuple ;
30
- import org .elasticsearch .common .joda .JodaDateFormatter ;
31
30
import org .elasticsearch .common .regex .Regex ;
32
31
import org .elasticsearch .common .settings .Settings ;
32
+ import org .elasticsearch .common .time .DateFormatter ;
33
+ import org .elasticsearch .common .time .DateFormatters ;
33
34
import org .elasticsearch .common .time .DateMathParser ;
34
- import org .elasticsearch .common .time .DateUtils ;
35
35
import org .elasticsearch .common .util .set .Sets ;
36
36
import org .elasticsearch .index .Index ;
37
37
import org .elasticsearch .index .IndexNotFoundException ;
38
38
import org .elasticsearch .index .IndexSettings ;
39
39
import org .elasticsearch .indices .IndexClosedException ;
40
40
import org .elasticsearch .indices .InvalidIndexNameException ;
41
- import org .joda .time .DateTimeZone ;
42
- import org .joda .time .format .DateTimeFormat ;
43
- import org .joda .time .format .DateTimeFormatter ;
44
41
42
+ import java .time .ZoneId ;
45
43
import java .util .ArrayList ;
46
44
import java .util .Arrays ;
47
45
import java .util .Collection ;
48
46
import java .util .Collections ;
49
47
import java .util .HashMap ;
50
48
import java .util .HashSet ;
51
49
import java .util .List ;
52
- import java .util .Locale ;
53
50
import java .util .Map ;
54
51
import java .util .Objects ;
55
52
import java .util .Set ;
@@ -66,10 +63,10 @@ public class IndexNameExpressionResolver {
66
63
public IndexNameExpressionResolver (Settings settings ) {
67
64
dateMathExpressionResolver = new DateMathExpressionResolver (settings );
68
65
expressionResolvers = Arrays .asList (
69
- dateMathExpressionResolver ,
70
- new WildcardExpressionResolver ());
66
+ dateMathExpressionResolver ,
67
+ new WildcardExpressionResolver ()
68
+ );
71
69
}
72
-
73
70
74
71
/**
75
72
* Same as {@link #concreteIndexNames(ClusterState, IndicesOptions, String...)}, but the index expressions and options
@@ -848,22 +845,23 @@ private static List<String> resolveEmptyOrTrivialWildcard(IndicesOptions options
848
845
849
846
static final class DateMathExpressionResolver implements ExpressionResolver {
850
847
848
+ private static final DateFormatter DEFAULT_DATE_FORMATTER = DateFormatters .forPattern ("uuuu.MM.dd" );
851
849
private static final String EXPRESSION_LEFT_BOUND = "<" ;
852
850
private static final String EXPRESSION_RIGHT_BOUND = ">" ;
853
851
private static final char LEFT_BOUND = '{' ;
854
852
private static final char RIGHT_BOUND = '}' ;
855
853
private static final char ESCAPE_CHAR = '\\' ;
856
854
private static final char TIME_ZONE_BOUND = '|' ;
857
855
858
- private final DateTimeZone defaultTimeZone ;
856
+ private final ZoneId defaultTimeZone ;
859
857
private final String defaultDateFormatterPattern ;
860
- private final DateTimeFormatter defaultDateFormatter ;
858
+ private final DateFormatter defaultDateFormatter ;
861
859
862
860
DateMathExpressionResolver (Settings settings ) {
863
861
String defaultTimeZoneId = settings .get ("date_math_expression_resolver.default_time_zone" , "UTC" );
864
- this .defaultTimeZone = DateTimeZone . forID (defaultTimeZoneId );
865
- defaultDateFormatterPattern = settings .get ("date_math_expression_resolver.default_date_format" , "YYYY .MM.dd" );
866
- this .defaultDateFormatter = DateTimeFormat .forPattern (defaultDateFormatterPattern );
862
+ this .defaultTimeZone = ZoneId . of (defaultTimeZoneId );
863
+ defaultDateFormatterPattern = settings .get ("date_math_expression_resolver.default_date_format" , "8uuuu .MM.dd" );
864
+ this .defaultDateFormatter = DateFormatter .forPattern (defaultDateFormatterPattern );
867
865
}
868
866
869
867
@ Override
@@ -930,11 +928,10 @@ String resolveExpression(String expression, final Context context) {
930
928
int dateTimeFormatLeftBoundIndex = inPlaceHolderString .indexOf (LEFT_BOUND );
931
929
String mathExpression ;
932
930
String dateFormatterPattern ;
933
- DateTimeFormatter dateFormatter ;
934
- final DateTimeZone timeZone ;
931
+ DateFormatter dateFormatter ;
932
+ final ZoneId timeZone ;
935
933
if (dateTimeFormatLeftBoundIndex < 0 ) {
936
934
mathExpression = inPlaceHolderString ;
937
- dateFormatterPattern = defaultDateFormatterPattern ;
938
935
dateFormatter = defaultDateFormatter ;
939
936
timeZone = defaultTimeZone ;
940
937
} else {
@@ -947,23 +944,25 @@ String resolveExpression(String expression, final Context context) {
947
944
inPlaceHolderString );
948
945
}
949
946
mathExpression = inPlaceHolderString .substring (0 , dateTimeFormatLeftBoundIndex );
950
- String patternAndTZid =
947
+ String dateFormatterPatternAndTimeZoneId =
951
948
inPlaceHolderString .substring (dateTimeFormatLeftBoundIndex + 1 , inPlaceHolderString .length () - 1 );
952
- int formatPatternTimeZoneSeparatorIndex = patternAndTZid .indexOf (TIME_ZONE_BOUND );
949
+ int formatPatternTimeZoneSeparatorIndex = dateFormatterPatternAndTimeZoneId .indexOf (TIME_ZONE_BOUND );
953
950
if (formatPatternTimeZoneSeparatorIndex != -1 ) {
954
- dateFormatterPattern = patternAndTZid .substring (0 , formatPatternTimeZoneSeparatorIndex );
955
- timeZone = DateTimeZone .forID (patternAndTZid .substring (formatPatternTimeZoneSeparatorIndex + 1 ));
951
+ dateFormatterPattern
952
+ = dateFormatterPatternAndTimeZoneId .substring (0 , formatPatternTimeZoneSeparatorIndex );
953
+ timeZone = ZoneId .of (
954
+ dateFormatterPatternAndTimeZoneId .substring (formatPatternTimeZoneSeparatorIndex + 1 ));
956
955
} else {
957
- dateFormatterPattern = patternAndTZid ;
956
+ dateFormatterPattern = dateFormatterPatternAndTimeZoneId ;
958
957
timeZone = defaultTimeZone ;
959
958
}
960
- dateFormatter = DateTimeFormat .forPattern (dateFormatterPattern );
959
+ dateFormatter = DateFormatter .forPattern (dateFormatterPattern );
961
960
}
962
- DateTimeFormatter parser = dateFormatter .withLocale (Locale .ROOT ).withZone (timeZone );
963
- JodaDateFormatter formatter = new JodaDateFormatter (dateFormatterPattern , parser , parser );
961
+ DateFormatter formatter = dateFormatter .withZone (timeZone );
964
962
DateMathParser dateMathParser = formatter .toDateMathParser ();
965
- long millis = dateMathParser .parse (mathExpression , context ::getStartTime , false ,
966
- DateUtils .dateTimeZoneToZoneId (timeZone ));
963
+ long millis = dateMathParser .parse (mathExpression , context ::getStartTime , false , timeZone );
964
+
965
+
967
966
String time = formatter .formatMillis (millis );
968
967
beforePlaceHolderSb .append (time );
969
968
inPlaceHolderSb = new StringBuilder ();
@@ -1007,18 +1006,4 @@ String resolveExpression(String expression, final Context context) {
1007
1006
return beforePlaceHolderSb .toString ();
1008
1007
}
1009
1008
}
1010
-
1011
- /**
1012
- * Returns <code>true</code> iff the given expression resolves to the given index name otherwise <code>false</code>
1013
- */
1014
- public final boolean matchesIndex (String indexName , String expression , ClusterState state ) {
1015
- final String [] concreteIndices = concreteIndexNames (state , IndicesOptions .lenientExpandOpen (), expression );
1016
- for (String index : concreteIndices ) {
1017
- if (Regex .simpleMatch (index , indexName )) {
1018
- return true ;
1019
- }
1020
- }
1021
- return indexName .equals (expression );
1022
- }
1023
-
1024
1009
}
0 commit comments