S
S
stufsdf2018-10-12 11:29:12
Java
stufsdf, 2018-10-12 11:29:12

How to create multiple types in elasticsearch via Spring Data?

How to create multiple types in elasticsearch via Spring Data?
As I understand it, an index in elastic is like a database name, and a type is a table, but when I create entities in java, I get this error:

Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [aaa, bbb]

If you change the name of the index, then everything works, what can be and what is the solution?
Here is an example code:
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "xxx", type = "aaa")
public class Temp1 {

    @Id
    private String id;

    private String name;

    private Long cost;
}

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

@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "xxx", type = "bbb")
public class Temp2 {

    @Id
    private Long id;

    private Boolean status;

    private Integer age;
}

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface Temp1Repo extends ElasticsearchRepository<Temp1, String> {
}

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface Temp2Repo extends ElasticsearchRepository<Temp2, String> {
}

org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'temp1Repo': 
Invocation of init method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]:
 Constructor threw exception; nested exception is java.lang.IllegalArgumentException:
 Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [aaa, bbb]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2018-10-12
@stufsdf

for some time now, elastic has banned several types for one index. Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. - https://www.elastic.co/guide/en/elasticsearch/refe...
if nested property does not suit you, then you need to fence several indexes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question