Search in sources :

Example 6 with FormatDateTimeFormatter

use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.

the class SimpleJodaTests method testThatEpochParserIsPrinter.

public void testThatEpochParserIsPrinter() {
    FormatDateTimeFormatter formatter = Joda.forPattern("epoch_millis");
    assertThat(formatter.parser().isPrinter(), is(true));
    assertThat(formatter.printer().isPrinter(), is(true));
    FormatDateTimeFormatter epochSecondFormatter = Joda.forPattern("epoch_second");
    assertThat(epochSecondFormatter.parser().isPrinter(), is(true));
    assertThat(epochSecondFormatter.printer().isPrinter(), is(true));
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter)

Example 7 with FormatDateTimeFormatter

use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.

the class SimpleJodaTests method testSlashInFormat.

public void testSlashInFormat() {
    FormatDateTimeFormatter formatter = Joda.forPattern("MM/yyyy");
    formatter.parser().parseMillis("01/2001");
    formatter = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
    long millis = formatter.parser().parseMillis("1970/01/01 00:00:00");
    formatter.printer().print(millis);
    try {
        millis = formatter.parser().parseMillis("1970/01/01");
        fail();
    } catch (IllegalArgumentException e) {
    // it really can't parse this one
    }
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter)

Example 8 with FormatDateTimeFormatter

use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.

the class SimpleJodaTests method testMultipleDifferentFormats.

public void testMultipleDifferentFormats() {
    FormatDateTimeFormatter formatter = Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd");
    String input = "1970/01/01 00:00:00";
    long millis = formatter.parser().parseMillis(input);
    assertThat(input, is(formatter.printer().print(millis)));
    Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||dateOptionalTime");
    Joda.forPattern("dateOptionalTime||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd");
    Joda.forPattern("yyyy/MM/dd HH:mm:ss||dateOptionalTime||yyyy/MM/dd");
    Joda.forPattern("date_time||date_time_no_millis");
    Joda.forPattern(" date_time || date_time_no_millis");
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 9 with FormatDateTimeFormatter

use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.

the class RootObjectMapper method doXContent.

@Override
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    final boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
    if (dynamicDateTimeFormatters.explicit() || includeDefaults) {
        builder.startArray("dynamic_date_formats");
        for (FormatDateTimeFormatter dateTimeFormatter : dynamicDateTimeFormatters.value()) {
            builder.value(dateTimeFormatter.format());
        }
        builder.endArray();
    }
    if (dynamicTemplates.explicit() || includeDefaults) {
        builder.startArray("dynamic_templates");
        for (DynamicTemplate dynamicTemplate : dynamicTemplates.value()) {
            builder.startObject();
            builder.field(dynamicTemplate.name(), dynamicTemplate);
            builder.endObject();
        }
        builder.endArray();
    }
    if (dateDetection.explicit() || includeDefaults) {
        builder.field("date_detection", dateDetection.value());
    }
    if (numericDetection.explicit() || includeDefaults) {
        builder.field("numeric_detection", numericDetection.value());
    }
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter)

Example 10 with FormatDateTimeFormatter

use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.

the class FieldStats method readFrom.

public static FieldStats readFrom(StreamInput in) throws IOException {
    byte type = in.readByte();
    long maxDoc = in.readLong();
    long docCount = in.readLong();
    long sumDocFreq = in.readLong();
    long sumTotalTermFreq = in.readLong();
    boolean isSearchable = in.readBoolean();
    boolean isAggregatable = in.readBoolean();
    boolean hasMinMax = true;
    if (in.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
        hasMinMax = in.readBoolean();
    }
    switch(type) {
        case 0:
            if (hasMinMax) {
                return new Long(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, in.readLong(), in.readLong());
            } else {
                return new Long(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
            }
        case 1:
            if (hasMinMax) {
                return new Double(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, in.readDouble(), in.readDouble());
            } else {
                return new Double(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
            }
        case 2:
            if (hasMinMax) {
                FormatDateTimeFormatter formatter = Joda.forPattern(in.readString());
                return new Date(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, formatter, in.readLong(), in.readLong());
            } else {
                return new Date(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
            }
        case 3:
            if (hasMinMax) {
                return new Text(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, in.readBytesRef(), in.readBytesRef());
            } else {
                return new Text(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
            }
        case 4:
            {
                if (hasMinMax == false) {
                    return new Ip(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
                }
                int l1 = in.readByte();
                byte[] b1 = new byte[l1];
                in.readBytes(b1, 0, l1);
                int l2 = in.readByte();
                byte[] b2 = new byte[l2];
                in.readBytes(b2, 0, l2);
                InetAddress min = InetAddressPoint.decode(b1);
                InetAddress max = InetAddressPoint.decode(b2);
                return new Ip(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, min, max);
            }
        case 5:
            {
                if (hasMinMax == false) {
                    return new GeoPoint(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable);
                }
                org.elasticsearch.common.geo.GeoPoint min = new org.elasticsearch.common.geo.GeoPoint(in.readDouble(), in.readDouble());
                org.elasticsearch.common.geo.GeoPoint max = new org.elasticsearch.common.geo.GeoPoint(in.readDouble(), in.readDouble());
                return new GeoPoint(maxDoc, docCount, sumDocFreq, sumTotalTermFreq, isSearchable, isAggregatable, min, max);
            }
        default:
            throw new IllegalArgumentException("Unknown type.");
    }
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter) InetAddress(java.net.InetAddress)

Aggregations

FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)19 DateTime (org.joda.time.DateTime)3 LocalDateTime (org.joda.time.LocalDateTime)3 MutableDateTime (org.joda.time.MutableDateTime)3 Settings (org.elasticsearch.common.settings.Settings)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 InetAddress (java.net.InetAddress)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)1 DocValueFormat (org.elasticsearch.search.DocValueFormat)1 SearchParseException (org.elasticsearch.search.SearchParseException)1 SearchContext (org.elasticsearch.search.internal.SearchContext)1 Instant (org.joda.time.Instant)1