【发布时间】:2022-01-08 08:13:23
【问题描述】:
我试图向现有索引(用户)添加一个新字段(bioAuto)。我有这个索引的 POJO:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
import java.time.LocalDateTime;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = IndexName.USERS)
@Setting(settingPath = "elastic/autocomplete_settings.json")
public class User {
@Id
private Long id;
@Field(type = FieldType.Search_As_You_Type)
private String userName;
@Field(type = FieldType.Text, analyzer = "autocomplete_whitespace_only", searchAnalyzer = "autocomplete_search")
private String bioAuto;
}
已创建字段,但类型错误,未连接到我的自定义分析器(在elastic/autocomplete_settings.json 中定义)。
创建的字段类型:
"bioAuto" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
正确的字段类型:
"bioAuto" : {
"type" : "text",
"analyzer" : "autocomplete_whitespace_only",
"search_analyzer" : "autocomplete_search"
},
如果我重新创建索引(删除用户索引并再次运行应用程序),一切正常。 ElasticCloud:7.9.3,Spring Data 版本:4.2.6
附:如果我执行此命令,一切正常,在 Spring Data Elastic 中使用正确类型自动创建字段的问题
PUT /users/_mapping
{
"properties": {
"bioAuto" : {
"type" : "text",
"analyzer" : "autocomplete_whitespace_only",
"search_analyzer" : "autocomplete_search"
}
}
}
【问题讨论】:
标签: java spring elasticsearch spring-data spring-data-elasticsearch