@Field(type=FieldType.keyword) being ignored on certain properties

Tho*_*ler 6 elasticsearch spring-data-elasticsearch

I'm having trouble with the way SD Elasticsearch is creating some of my indices on application startup. I've got some String fields that I want to be of type "keyword" but they are always being created as type "text". This is using Elasticsearch 5.5.1, Spring 5.0.0, Spring Data Kay-RELEASE.

As an example I've got something like follows:

// DepartmentSearchResult.java
@Document(indexName = "hr_index", type = "department", createIndex = false)
public class DepartmentSearchResult implements Serializable {
    @Id private String id;

    private String foo;
    // other fields, getters, setters etc. omitted
}

// DepartmentSearchingRepository.java
public interface DepartmentSearchingRepository extends ElasticsearchRepository<DepartmentSearchResult, String> {}

// ApplicationStartupListener.java
@Component
public class ApplicationStartupListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired ElasticsearchTempalte elasticSearchTemplate;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (!elasticSearchTemplate.indexExists(DepartmentSearchResult.class)) {
            elasticSearchTemplate.createIndex(DepartmentSearchResult.class);
            elasticSearchTemplate.putMapping(DepartmentSearchResult.class);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

(I've set createIndex to false and have the ApplicationStartupListener instead due to an issue I asked about at How to correctly address "can't add a _parent field that points to an already existing type, that isn't already a parent" on app startup. Including it here in case this is somehow related.)

Anyway, I want DepartmentSearchResult.id to be keyword, not text. So, I've changed from:

@Id private String id;
Run Code Online (Sandbox Code Playgroud)

to:

@Field(type=FieldType.keyword) @Id private String id;
Run Code Online (Sandbox Code Playgroud)

I then drop the index and restart my app. The index and the mapping are created, but "id" is always created as text, not keyword. Other fields are working properly; if I change foo to @Field(type=FieldType.keyword) private String foo; that shows up as keyword in the mapping, it's just this id field that I can't get working.

My current workaround is to just create the mapping manually like:

curl -s -X PUT http://localhost:9200/hr_index/_mapping/department -d '{
    "properties": {
        "id": {
            "type": "keyword"
        }
    }
}'
Run Code Online (Sandbox Code Playgroud)

and that works, but I'd much prefer for Spring to just create the mapping on the fly so I don't need to maintain a separate mapping installation script. Any places I should be looking that might indicate why this field keeps getting created as "text"?