Search code examples
javaspringspring-data-elasticsearch

Spring Data Elasticsearch - Create keyword field with normalizer


We are using the spring-data-elasticsearch project to interface with our elasticsearch clusters, and have been using it now for around a year. Recently, we moved to elasticsearch 5.x (from 2.x) where we now have the "keyword" datatype.

I would like to index these keywords as lowercase values, which I know can be done with field normalizers. I can't find anywhere in the documentation or online where I can add a normalizer to a field through the annotation based mapping. E.g

@Field(type = FieldType.keyword, <some_other_param = some_normalizer>)

Is this something that can be done? I know that we can use JSON based mapping definitions as well, so I will fall back to that option if needed, but would like to be able to do it this way if possible.

Any help would be very appreciated!


Solution

  • FYI, for anyone looking at this, the answer is there is not a way to do this at this time.

    You can do this, however, by creating your mappings file as JSON in the Elasticsearch format. See: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

    You can then create that JSON file and link it to your Domain model with.

    @Mapping(mappingPath = "some/path/mapping.json")

    Note that this is not, in my experience, compatible with the provided annotation based mapping for fields.