Kotlin 忽略嵌套对象上的Spring数据弹性搜索多字段注释
我创建了一个Kotlin 忽略嵌套对象上的Spring数据弹性搜索多字段注释,kotlin,
spring-data-elasticsearch,Kotlin,
spring Data Elasticsearch,我创建了一个asciifolding.json文件,其中保存了“忽略重音”分析器的配置 我在顶级对象的字段上使用了@MultiField注释,这样做没有问题 但是,当我在嵌套对象的字段上使用相同的注释时,它将被忽略 @Document(indexName = "indexName") @Setting(settingPath = "asciifolding.json") class TopLevelObject( @Id val id: Str
asciifolding.json
文件,其中保存了“忽略重音”分析器的配置
我在顶级对象的字段上使用了@MultiField
注释,这样做没有问题
但是,当我在嵌套对象的字段上使用相同的注释时,它将被忽略
@Document(indexName = "indexName")
@Setting(settingPath = "asciifolding.json")
class TopLevelObject(
@Id
val id: String,
// ----------------------------------------------------------- THIS WORKS
@MultiField(
mainField = Field(type = FieldType.Text, analyzer = "ascii_folding"),
otherFields = [
InnerField(type = FieldType.Keyword, suffix = "keyword")
]
)
val name: String,
val nestedObject: NestedObject
)
@Setting(settingPath = "asciifolding.json")
class NestedObject(
val aField: String,
// --------------------------------------------------------- THIS DOESN'T
@MultiField(
mainField = Field(type = FieldType.Text, analyzer = "ascii_folding"),
otherFields = [
InnerField(type = FieldType.Keyword, suffix = "keyword")
]
)
val anotherField: String
)
GET/indexName/_映射的结果:
{
"indexName": {
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "ascii_folding" // APPEARS HERE
},
"nestedObject": {
"properties": {
"aField": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"anotherField": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
} // DOESN'T HERE
}
}
}
}
}
}
}
<关于我丢失什么的想法? 映射生成器不会考虑没有用<代码> @字段< /代码>注释的属性。因此,您需要添加以下内容:
@Document(indexName = "indexName")
@Setting(settingPath = "asciifolding.json")
class TopLevelObject(
@Id
val id: String,
// ----------------------------------------------------------- THIS WORKS
@MultiField(
mainField = Field(type = FieldType.Text, analyzer = "ascii_folding"),
otherFields = [
InnerField(type = FieldType.Keyword, suffix = "keyword")
]
)
val name: String,
@Field(type = FieldType.Nested) // <-- !!! add this field type definition
val nestedObject: NestedObject
)
@文档(indexName=“indexName”)
@设置(settingPath=“ascifolding.json”)
类TopLevelObject(
@身份证
valid:String,
//--------------------------------------------------------------这很有效
@多场(
mainField=Field(type=FieldType.Text,analyzer=“ascii\U折叠”),
其他字段=[
InnerField(type=FieldType.Keyword,后缀=“Keyword”)
]
)
val name:String,
@字段(类型=字段类型.嵌套)//