Search code examples
spring-bootelasticsearchspring-data-elasticsearch

spring-data-elasticsearch entity removing deprecated type


Elasticsearch will remove _type in version 8. I am developing a Spring boot microservice, using ElasticRepository, so I would like to set up the Entity in order not to use it. As far as I know, if you do not implicitly specify a type in @Document, it will take the class name in lower case.

How do I specify not to use a type instead type = "_doc"?

Elastic Search: 7.5.1 Spring boot: 2.2.1

package org.elastic.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@SuppressWarnings("unused")

@Document(indexName = "basic_data",type = "_doc")
public class BasicData {

    @Id
    private String id;
    private String field1;
    private String field2;
}

Solution

  • Spring Boot 2.2.1 and the corresponding Spring Data Elasticsearch 3.2.x use the Elasticsearch 6.8.5 libraries. You won't be able to use this versions with a Elasticsearch 7 cluster, the client libraries of 6.8 are not compatible to a server in version 7.

    In the next version of Spring Data Elasticsearch which should be released this spring, the targeted Elasticsearch version is 7.5 (I will update this to 7.6 in the next days). There we have deprecated the code where the user puts the type information (for example in the @Documentannotation) and we don't use it anymore in the underlying calls to Elasticsearch. So for the time being you can leave it in the annotation for the next version to come.

    Once Elasticsearch 8 is released our then next version of Spring Data Elasticsearch will use that and then we will probably remove this from our code as well to clean up.