Mike
Mike

Reputation: 111

Hibernate search 6 custom index settings

I would like to configure a custom tokenizer for using in my custom analyzer in Hibernate Search (6.0.8) with Spring Boot 2.5.x. According to the documentation (https://docs.jboss.org/hibernate/search/6.1/reference/en-US/html_single/#_custom_index_settings) I should use custom index settings like this:

spring:
  jpa:
    properties:
      hibernate:
        search:
          enabled: true
          backend:
            indexes:
              Lemma:
                analysis:
                  configurer: class:**.**.CustomAnalysisConfigurer
                schema_management:
                  settings_file: custom/index-settings.json

my custom/index-settings.json looks like

{
  "analysis": {
    "tokenizer": {
      "custom_ngram_tokenizer": {
        "type": "ngram",
        "min_gram": "2",
        "max_gram": "3"
      }
    }
  }
}

And the CustomAnalysisConfigurer looks like

package ***.elasticsearch

import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer

class CustomAnalysisConfigurer : ElasticsearchAnalysisConfigurer {
    override fun configure(context: ElasticsearchAnalysisConfigurationContext) {
        context.analyzer("customAnalyzer").custom().tokenizer("custom_ngram_tokenizer")
    }
}

And I would like to call it in my Entity like @FullTextField(analyzer = "customAnalyzer")

When I use a default available tokenizer (like ngram) in CustomAnalysisConfigurer everything works fine. But I expect Hibernate will create an index for me with the settings from custom/index-settings.json. It looks like the file isn't picked up at all. Also tried:

spring:
  jpa:
    properties:
      hibernate:
        search:
          enabled: true
          backend:
            analysis:
              configurer: class:**.**.CustomAnalysisConfigurer
            schema_management:
              settings_file: custom/index-settings.json

settings valid for all indexes. But this is also without the wanted result.

PS **.** is just for masking ;)

Upvotes: 1

Views: 628

Answers (1)

Mike
Mike

Reputation: 111

This was not working for 6.0.x but it was mentioned in the docs. I found out there was also a 6.1.x version of Hibernate Search and this version was working as expected.

Upvotes: 2

Related Questions