Munish Chandel
Munish Chandel

Reputation: 3702

Spring Data ElasticSearch - Index single field multiple times

I want to index a single field (name) multiple times with different analyzers (ngram and standard) so that I can search using partial words or full words. But I could not find Spring Data ElasticSearch's support for this. Since @Field annotation can not be repeated, so how can I achieve this using Spring Data?

Upvotes: 0

Views: 998

Answers (1)

aditya gupta
aditya gupta

Reputation: 433

import org.springframework.data.elasticsearch.annotations.InnerField;
   import org.springframework.data.elasticsearch.annotations.MultiField;

        @MultiField(
                  mainField = @Field(type = FieldType.String),
                  otherFields = {
                      @InnerField(index = FieldIndex.not_analyzed, suffix = "<suffix name>", type =FieldType.String)
                  }
                )
        private String <fieldname>;

This way you can store the same field multiple times with different analyzers, please remember to use the meaningful suffix name for searching that field

for more information please refer the following link:

https://www.baeldung.com/spring-data-elasticsearch-queries

Upvotes: 2

Related Questions