Search code examples
spring-data-elasticsearch

Spring-data-elasticsearch @CompletionField does not create mapping type Completion


I am using annotation @CompletionField from Spring Data Elasticsearch (4.0.1 RELEASE) in my entity, but it looks the ElasticSearch index is created with wrong mapping.

Entity

@Document(indexName="address")
public class Address {
    @CompletionField
    private String cityName;
}

Repository

@Service
public interface AddressRepository extends ElasticsearchRepository<Address, String> {
}

Index is autocreated by calling repository.save(address)

Snippet from elasticsearch mapping

"cityName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}

As you can see there is missing type "completion" (see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#completion-suggester).

Did I miss something?


Solution

  • The @CompletionField must be of type Completion:

    @Document(indexName="address")
    public class Address {
    
        @CompletionField
        private Completion cityName;
    
    }
    

    You might want to check the test code for this functionality