Elastic search case insensitive

Elastic search case insensitive

I have the following annotation based elastic search configuration, I’ve set the index not to be analyzed because I don’t want these fields to be tokenized:
@Document(indexName = “abc”, type = “efg”)
public class ResourceElasticSearch {
private String id;
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String name;
@Field(type = FieldType.String, store = true)
private List tags = new ArrayList<>();
@Field(type = FieldType.String)
private String clientId;
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String virtualPath;
@Field(type = FieldType.Date)
private Date lastModifiedTime;
@Field(type = FieldType.Date)
private Date lastQueryTime;
@Field(type = FieldType.String)
private String modificationId;
@Field(type = FieldType.String)
private String realPath;
@Field(type = FieldType.String)
private String extension;
@Field(type = FieldType.String)
private ResourceType type;

Is it possible by using annotations to make the searches on the name, virtualPath and tags to be case-insensitive?
The search looks like this, search by wildcard is required:
private QueryBuilder getQueryBuilderForSearch(SearchCriteria criteria) {
String virtualPath = criteria.getPath();

return boolQuery()
.must(wildcardQuery(“virtualPath”, virtualPath))
.must(wildcardQuery(“name”, criteria.getName()));


Solution 1:

Not really possible what you want to do and it’s not about Spring Data configuration, it’s about Elasticsearch itself: you indexed data as not_analyzed and it will stay that way.

Also, if you wanted case insensitive data I suggest indexing with keyword analyzer combined with a lowercase token filter.

Solution 2:

I’ve found something based on Andrei Stefan’s suggestion which has a similar result to using the annotations:

    public Client client() throws IOException {
    TransportClient client = new TransportClient();
    TransportAddress address = new InetSocketTransportAddress(env.getProperty("elasticsearch.host"), Integer.parseInt(env.getProperty("elasticsearch.port")));

    XContentBuilder settingsBuilder = XContentFactory.jsonBuilder()
            .field("tokenizer", "keyword")
            .array("filter", "lowercase")
    if (!client.admin().indices().prepareExists("abc").execute().actionGet().isExists()) {
       return client;


Related:  NEST Elasticsearch Reindex examples