@stufsdf

Как создать в elasticsearch несколько типов через Spring Data?

Как создать в elasticsearch несколько типов через Spring Data?
Как я понимаю, индекс в еластике - это наподобие имени базы данных, а тип это таблица, но когда создаю сущности в java то такая ошибка:
Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [aaa, bbb]


Если поменять имя индекса, то все работает, что может быть и какое есть решение?

Вот пример кода:

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]
  • Вопрос задан
  • 1220 просмотров
Решения вопроса 1
@aol-nnov
с некоторых пор в эластике запретили несколько типов на один индекс. Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. - https://www.elastic.co/guide/en/elasticsearch/refe...

если nested property тебе не подходит, то надо городить несколько индексов
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
19 апр. 2024, в 15:01
35000 руб./за проект
19 апр. 2024, в 14:12
30000 руб./за проект