0
votes

We have a use case where we want to use certain indices in different cluster so as to improve performance. We are using java based configuration for elasticsearch.

@Log4j
@Configuration
@EnableElasticsearchRepositories(basePackages = ["com.as.core.repositories"])
class ElasticSearchConfig {

@Bean
ElasticsearchOperations elasticsearchTemplate() {
    Client client
    Settings settings


    InetSocketTransportAddress inetSocketTransportAddress = new InetSocketTransportAddress(
            Holders.config.grails.elasticsearch.transportClientIP as String,
            Holders.config.grails.elasticsearch.transportClientPort as Integer
    )

        settings = ImmutableSettings.settingsBuilder()
                .put("cluster.name", "elasticsearch")
                .build()
        client = new TransportClient(settings)
                .addTransportAddress(inetSocketTransportAddress)



    return new ElasticsearchTemplate(client)
    }
}
  • Is there any way so that we can add configurations of a different elastic-search cluster?
  • Spring data automatically creates indices in the specified cluster. How is the creation of indices managed in multi cluster application?

What I have googled is there is method addTransportAddresses(inetSocketTransportAddress) which allow us to add an array of elastic search server addresses.

  • But how will we specify multiple cluster names?
1

1 Answers

1
votes

Nothing prevents you from creating several clients to different clusters.

In your ElasticSearchConfig class, simply declare a second method elasticsearchTemplate2() which returns another instance of ElasticsearchTemplate embedding another Client to another cluster.

Then you call one method or the other depending on where you need to create your indices.