0

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?

1 Answer 1

2
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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.