2727import org .elasticsearch .common .Strings ;
2828import org .elasticsearch .common .collect .ImmutableOpenMap ;
2929import org .elasticsearch .common .collect .Tuple ;
30- import org .elasticsearch .common .joda .JodaDateFormatter ;
3130import org .elasticsearch .common .regex .Regex ;
3231import org .elasticsearch .common .settings .Settings ;
32+ import org .elasticsearch .common .time .DateFormatter ;
33+ import org .elasticsearch .common .time .DateFormatters ;
3334import org .elasticsearch .common .time .DateMathParser ;
34- import org .elasticsearch .common .time .DateUtils ;
3535import org .elasticsearch .common .util .set .Sets ;
3636import org .elasticsearch .index .Index ;
3737import org .elasticsearch .index .IndexNotFoundException ;
3838import org .elasticsearch .index .IndexSettings ;
3939import org .elasticsearch .indices .IndexClosedException ;
4040import org .elasticsearch .indices .InvalidIndexNameException ;
41- import org .joda .time .DateTimeZone ;
42- import org .joda .time .format .DateTimeFormat ;
43- import org .joda .time .format .DateTimeFormatter ;
4441
42+ import java .time .ZoneId ;
4543import java .util .ArrayList ;
4644import java .util .Arrays ;
4745import java .util .Collection ;
4846import java .util .Collections ;
4947import java .util .HashMap ;
5048import java .util .HashSet ;
5149import java .util .List ;
52- import java .util .Locale ;
5350import java .util .Map ;
5451import java .util .Objects ;
5552import java .util .Set ;
@@ -66,10 +63,10 @@ public class IndexNameExpressionResolver {
6663 public IndexNameExpressionResolver (Settings settings ) {
6764 dateMathExpressionResolver = new DateMathExpressionResolver (settings );
6865 expressionResolvers = Arrays .asList (
69- dateMathExpressionResolver ,
70- new WildcardExpressionResolver ());
66+ dateMathExpressionResolver ,
67+ new WildcardExpressionResolver ()
68+ );
7169 }
72-
7370
7471 /**
7572 * Same as {@link #concreteIndexNames(ClusterState, IndicesOptions, String...)}, but the index expressions and options
@@ -848,22 +845,23 @@ private static List<String> resolveEmptyOrTrivialWildcard(IndicesOptions options
848845
849846 static final class DateMathExpressionResolver implements ExpressionResolver {
850847
848+ private static final DateFormatter DEFAULT_DATE_FORMATTER = DateFormatters .forPattern ("uuuu.MM.dd" );
851849 private static final String EXPRESSION_LEFT_BOUND = "<" ;
852850 private static final String EXPRESSION_RIGHT_BOUND = ">" ;
853851 private static final char LEFT_BOUND = '{' ;
854852 private static final char RIGHT_BOUND = '}' ;
855853 private static final char ESCAPE_CHAR = '\\' ;
856854 private static final char TIME_ZONE_BOUND = '|' ;
857855
858- private final DateTimeZone defaultTimeZone ;
856+ private final ZoneId defaultTimeZone ;
859857 private final String defaultDateFormatterPattern ;
860- private final DateTimeFormatter defaultDateFormatter ;
858+ private final DateFormatter defaultDateFormatter ;
861859
862860 DateMathExpressionResolver (Settings settings ) {
863861 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 );
867865 }
868866
869867 @ Override
@@ -930,11 +928,10 @@ String resolveExpression(String expression, final Context context) {
930928 int dateTimeFormatLeftBoundIndex = inPlaceHolderString .indexOf (LEFT_BOUND );
931929 String mathExpression ;
932930 String dateFormatterPattern ;
933- DateTimeFormatter dateFormatter ;
934- final DateTimeZone timeZone ;
931+ DateFormatter dateFormatter ;
932+ final ZoneId timeZone ;
935933 if (dateTimeFormatLeftBoundIndex < 0 ) {
936934 mathExpression = inPlaceHolderString ;
937- dateFormatterPattern = defaultDateFormatterPattern ;
938935 dateFormatter = defaultDateFormatter ;
939936 timeZone = defaultTimeZone ;
940937 } else {
@@ -947,23 +944,25 @@ String resolveExpression(String expression, final Context context) {
947944 inPlaceHolderString );
948945 }
949946 mathExpression = inPlaceHolderString .substring (0 , dateTimeFormatLeftBoundIndex );
950- String patternAndTZid =
947+ String dateFormatterPatternAndTimeZoneId =
951948 inPlaceHolderString .substring (dateTimeFormatLeftBoundIndex + 1 , inPlaceHolderString .length () - 1 );
952- int formatPatternTimeZoneSeparatorIndex = patternAndTZid .indexOf (TIME_ZONE_BOUND );
949+ int formatPatternTimeZoneSeparatorIndex = dateFormatterPatternAndTimeZoneId .indexOf (TIME_ZONE_BOUND );
953950 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 ));
956955 } else {
957- dateFormatterPattern = patternAndTZid ;
956+ dateFormatterPattern = dateFormatterPatternAndTimeZoneId ;
958957 timeZone = defaultTimeZone ;
959958 }
960- dateFormatter = DateTimeFormat .forPattern (dateFormatterPattern );
959+ dateFormatter = DateFormatter .forPattern (dateFormatterPattern );
961960 }
962- DateTimeFormatter parser = dateFormatter .withLocale (Locale .ROOT ).withZone (timeZone );
963- JodaDateFormatter formatter = new JodaDateFormatter (dateFormatterPattern , parser , parser );
961+ DateFormatter formatter = dateFormatter .withZone (timeZone );
964962 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+
967966 String time = formatter .formatMillis (millis );
968967 beforePlaceHolderSb .append (time );
969968 inPlaceHolderSb = new StringBuilder ();
@@ -1007,18 +1006,4 @@ String resolveExpression(String expression, final Context context) {
10071006 return beforePlaceHolderSb .toString ();
10081007 }
10091008 }
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-
10241009}
0 commit comments