Search code examples
javaspringelasticsearchspring-dataspring-data-elasticsearch

Spring Data Elasticsearch MultiField's Mainfield name attribute not working


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 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!


Solution

  • This was fixed with this issue and was released in versions 4.0.3 and 4.1.M2