Skip to content

Why save epoch_millis as string? #2318

Closed
@puppylpg

Description

@puppylpg

I've noticed that if a field is Instant with epoch_millis format:

    @Field(type = FieldType.Date, format = DateFormat.epoch_millis)
    private Instant timestamp;

spring-data-elasticsearch will convert this object as a json with string value like "timestamp":"1644234181000" rather than long value "timestamp":1644234181000. After digging into the code, I find that it's DateFormatter#format that returns only string value, so timestamp in Instant is converted into a string value rather long.

  1. Although string value(long literally) for epoch_mills is accepted by elasticsearch, it's not mentioned in the doc;
  2. Worse, we save/update our value as long for epoch_millis before(without using spring-data-elasticsearch), so now after using spring-data-elasticsearch, both string and long exist for timestamp field;
  3. Additionally, we also use elasticsearch-hadoop to read data in elasticsearch, and it can only read epoch_millis as long or string, not both.

Any ideas to support to convert epoch_millis and epoch_second for date type as long rather than string? or at least supply an option to determine it as long or string, rather than just use string whatever the real date type is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions