Search code examples
javaelasticsearchspring-data-elasticsearch

Field @timestamp using Spring Data ElasticSearch


What I am trying to achieve:

  • insert document in ElasticSearch using Reactive Spring Data ElasticSearch with a field @timestamp (note the "at" @ sign for timestamp, it is @timestamp, not just timestamp).

What I tried:

@Repository
public interface ElasticRepository extends ReactiveCrudRepository<ElasticPojo, String> {

}
@Document(indexName = "theindex")
public class ElasticPojo {

    @Field(type = FieldType.Date)
    private long timestamp;

    @Id
    private String id;

Issue:

This will insert a timestamp field inside ElasticSearch, not @timestamp

How to insert a field @timestamp?


Solution

  • Check the documentation for the @Field annotation, it has a name parameter:

    @Field(name = "@timestamp", type = FieldType.Date)