我正在尝试使用spring-data-elasticsearch来设置类似于下面json配置的类型的映射,并且我遇到了问题。
{
"_id" : {
"type" : "string",
"path" : "id"
},
"properties":{
"addressName":{
"type":"multi_field",
"fields":{
"addressName":{
"type":"string"
},
"edge":{
"analyzer":"edge_search_analyzer",
"type":"string"
}
}
},
"companyName":{
"type":"multi_field",
"fields":{
"companyName":{
"type":"string"
},
"edge":{
"analyzer":"edge_search_analyzer",
"type":"string"
}
}
}
}
}
这是现在的实体类:
@Document(indexName = "test", type="address")
@Setting(settingPath="/config/elasticsearch/test.json") // Used to configure custom analyzer/filter
public class Address {
@Id
private Integer id;
@MultiField(
mainField = @Field(type = FieldType.String),
otherFields = {
@NestedField(dotSuffix = "edge", type = FieldType.String, indexAnalyzer = "edge_search_analyzer")
}
)
private String addressName;
@MultiField(
mainField = @Field(type = FieldType.String),
otherFields = {
@NestedField(dotSuffix = "edge", type = FieldType.String, indexAnalyzer = "edge_search_analyzer")
}
)
private String companyName;
public Address() {}
public Address(AddressDTO dto) {
id = dto.getId();
addressName = dto.getAddressName();
companyName = dto.getCompanyName();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
Preconditions.checkNotNull(id);
this.id = id;
}
public String getAddressName() {
return addressName;
}
public void setAddressName(String addressName) {
this.addressName = addressName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
}
我发现这会产生如下映射:
"address" : {
"properties" : {
"addressName" : {
"type" : "string",
"fields" : {
"addressName.edge" : {
"type" : "string",
"index_analyzer" : "edge_search_analyzer"
}
}
},
"companyName" : {
"type" : "string",
"fields" : {
"companyName.edge" : {
"type" : "string",
"index_analyzer" : "edge_search_analyzer"
}
}
}
}
}
这导致两个问题:
如果我添加以下内容以覆盖注释的使用,一切正常:
@Mapping(mappingPath="/config/elasticsearch/address.json")
其中“address.json”包含此帖子顶部的映射配置。
那么,任何人都能指出我可能会遇到的问题吗? 是否可以使用可用的注释,或者我将不得不坚持使用json配置?
此外,是否有通过spring-data-elasticsearch设置索引级配置的“正确”方法,还是不支持这种方法?目前,我正在为此目的使用@Setting注释