我有个人课:
@Document(indexName = "person")
@Data
@EqualsAndHashCode(callSuper = true)
public class Person extends BaseEntity implements Serializable {
@Field(type=FieldType.Keyword)
private String firstName;
@Field(type=FieldType.Keyword)
private String lastName;
@MultiField(
mainField = @Field(type = FieldType.Keyword),
otherFields = {
@InnerField(type = FieldType.Text, suffix = "ngrams", analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
})
private String fullName;
@Field
private String maidenName;
}
我有一个在启动期间创建索引的现有代码:
final IndexOperations indexOperations = this.elasticsearchOperations.indexOps(clazz);
indexOperations.putMapping();
现在,我需要从它生成映射并创建一次映射。有人能帮忙吗?我如何将其与现有代码集成,以包含字段的映射,使其成为静态的?
发布于 2022-11-04 07:35:04
只需检查是否需要创建索引,如果需要,创建它并编写映射:
indexOperations = operations.indexOps(entityClass);
if (!indexOperations.exists()) {
indexOperations.createWithMapping();
}
https://stackoverflow.com/questions/74313370
复制相似问题