Spring数据弹性搜索忽略嵌套对象上的MultiField注释



我创建了一个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
)

Result of GET/indexName/_mapping:

{
"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
}
}
}
}
}
}
}

你知道我错过了什么吗?

映射生成器不会考虑没有用@Field注释的属性。所以你需要加上这个:

@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
)

顺便说一句,@Setting注释只在定义索引的实体上检查,因此在顶层检查。它在嵌套类上被忽略。

最新更新