Search code examples
elasticsearchspring-data-elasticsearch

spring data elasticsearch how to create text field with child keyword field


spring data elasticsearch version: 2.4.1

when I use @Field(type = FieldType.Text), spring data will create a text field, but I also want to create a child keyword field. Like this:

{
    "text_field":{
        "type":"text",
        "fields":{
            "keyword":{
                "type":"keyword"
            }
        }
    }
}

Solution

  • There never was a version 2.4.1 of Spring Data Elasticsearch, I assume you mean Spring Boot 2.4.1? If so, that would use Spring Data Elasticsearch 4.1.2

    What you'd need define would be

    @MultiField(mainField = @Field(type = FieldType.Text),
       otherFields = { @InnerField(suffix = "keyword", type = FieldType.Keyword) })
    private String text_field;