英文:
Spring Data Elasticsearch MultiField's Mainfield name attribute not working
问题
我有一个使用Spring Data Elasticsearch v4.0.1的Spring Boot应用程序。如果我创建一个如下所示的文档类:
```java
@Document(indexName = "paystub")
public class PayStubEntity {
@MultiField(
mainField = @Field(type = Text, name = "account_number"),
otherFields = {@InnerField(suffix = "keyword", type = Keyword)})
private String acctNumber;
@Field(type = Keyword, name = "ccy")
private String currency;
...
生成的映射如下:
{
"paystub": {
"mappings": {
"properties": {
"acctNumber": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"ccy": {
"type": "keyword"
},
...
}
}
}
}
显然,货币字段上注解中的name属性值被用于索引和映射的创建,即"ccy"。但是对于主字段acctNumber上MultiField注解中的name属性似乎不是这种情况。
这里的文档1说明了Field注解的name属性将代表Elasticsearch文档字段的名称,如果未设置name属性,它将默认为注解字段的名称。
但是,当Field注解在MultiField注解内部使用时,似乎无法正常工作。
是否有解决这个问题的方法?
感谢您的帮助!
<details>
<summary>英文:</summary>
I have a spring boot application with Spring Data Elasticsearch v4.0.1. If I create a document class as such:
@Document(indexName = "paystub")
public class PayStubEntity {
@MultiField(
mainField = @Field(type = Text, name = "account_number"),
otherFields = {@InnerField(suffix = "keyword", type = Keyword)})
private String acctNumber;
@Field(type = Keyword, name = "ccy")
private String currency;
...
The resulting mapping is:
{
"paystub": {
"mappings": {
"properties": {
"acctNumber": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"ccy": {
"type": "keyword"
},
...
}
}
}
}
Clearly the name attribute value in the annotation on the currency field is being used in the index and mapping creation, i.e. "ccy". But this doesn't seem to be the case for the mainField's name attribute in the MultiField annotation on field acctNumber.
The documentation [here][1] states that the the name attribute of the Field annotation will represent the name of the field of Elasticsearch document, and if the name attribute is not set it will default to the name of the annotated field.
But this doesn't seem to work when the Field annotation is used within a Multifield annotation.
Is there a workaround for this?
Thanks for the help!
[1]: https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping
</details>
# 答案1
**得分**: 2
这个问题已经通过[这个问题](https://jira.spring.io/browse/DATAES-896) 得到了修复,并在版本4.0.3和4.1.M2中发布。
<details>
<summary>英文:</summary>
This was fixed with [this issue](https://jira.spring.io/browse/DATAES-896) and was released in versions 4.0.3 and 4.1.M2
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论