Spring Data Elasticsearch多字段的主字段名称属性不起作用

huangapple go评论69阅读模式
英文:

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. &quot;ccy&quot;.  But this doesn&#39;t seem to be the case for the mainField&#39;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&#39;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>



huangapple
  • 本文由 发表于 2020年9月3日 00:55:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63710185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定