Interface IndexAnalysisConfigurer


public interface IndexAnalysisConfigurer
Base interface for configurers of Elasticsearch analysis elements (analyzers, normalizers, etc).

Create Spring Bean that implements this interface.

Analysis elements can be configured inside configure(AnalysisConfigurationContext)

Example:

 @Component
 public class CustomIndexAnalysisConfigurer implements IndexAnalysisConfigurer {
      @Override
     public void configure(AnalysisConfigurationContext context) {
         // Analyzer
         context.defineAnalyzer("configured_builtin_analyzer")
                 .configureBuiltIn("standard")
                 .withParameter("max_token_length", 100)
                 .withParameter("stopwords", "_english_");

         context.defineAnalyzer("custom_analyzer")
                 .createCustom()
                 .withTokenizer("whitespace")
                 .withCharacterFilters("html_strip")
                 .withTokenFilters("stop");

         context.defineAnalyzer("analyzer_with_native_config")
                 .withNativeConfiguration(
                         "{" +
                                 "\"type\": \"standard\"," +
                                 "  \"max_token_length\": 100," +
                                 "  \"stopwords\": \"_english_\"" +
                                 "}"
                 );

         // Normalizer
         context.defineNormalizer("custom_normalizer")
                 .createCustom()
                 .withCharacterFilters("html_strip")
                 .withTokenFilters("lowercase");

         context.defineNormalizer("normalizer_with_native_config")
                 .withNativeConfiguration(
                         "{" +
                                 "  \"type\": \"custom\"," +
                                 "  \"filter\": [" +
                                 "    \"lowercase\"," +
                                 "    \"asciifolding\"" +
                                 "  ]" +
                                 "}"
                 );

         // Tokenizer
         context.defineTokenizer("configured_tokenizer")
                 .configureBuiltIn("whitespace")
                 .withParameter("max_token_length", 100);

         context.defineTokenizer("tokenizer_with_native_config")
                 .withNativeConfiguration(
                         "{" +
                                 "  \"type\": \"standard\"," +
                                 "  \"max_token_length\": 100" +
                                 "}"
                 );

         // Character Filters
         context.defineCharacterFilter("configured_char_filter")
                 .configureBuiltIn("html_strip")
                 .withParameter("escaped_tags", Arrays.asList("b", "i"));

         context.defineCharacterFilter("char_filter_with_native_config")
                 .withNativeConfiguration(
                         "{" +
                                 "  \"type\": \"html_strip\"," +
                                 "  \"escaped_tags\": [" +
                                 "    \"b\"" +
                                 "  ]" +
                                 "}"
                 );

         // Token Filter
         context.defineTokenFilter("configured_token_filter")
                 .configureBuiltIn("stop")
                 .withParameter("stopwords", "_russian_")
                 .withParameter("ignore_case", "true");

         context.defineTokenFilter("filter_with_native_config")
                 .withNativeConfiguration(
                         "{" +
                                 "  \"type\": \"ngram\"," +
                                 "  \"min_gram\": 3," +
                                 "  \"max_gram\": 5" +
                                 "}"
                 );
     }
 }