Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up bonsai-elasticsearch in Jhipster - Heroku

After deploying to heroku my Jhipster app, I want to use cloud elasticsearch (Bonsai) with JHipster. Bonsai provides following env variable:

$BONSAI_URL 

How is this properly added in application-prod.yml? I`ve been reading the docs and trying too set it as cluster-nodes value and as host. But i'm a bit lost. Any tips are more than welcome.

application-prod.yml

spring:
devtools:
    restart:
        enabled: false
    livereload:
        enabled: false
datasource:
    url: jdbc:mysql://localhost:3306/App?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password:
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: MYSQL
    show_sql: false
    properties:
        hibernate.cache.use_second_level_cache: true
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: false
        hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
data:
    elasticsearch:
        network:
            host: ${BONSAI_URL}
        cluster-name:  VLT
        cluster-nodes: localhost:9300
mail:
    host: smtp.sendgrid.net
    port: 587
    username: ${SENDGRID_USERNAME}
    password: ${SENDGRID_PASSWORD}
    protocol: smtp
    tls: false
    auth: true
    from: [email protected]

thymeleaf:
    cache: true

liquibase:
contexts: prod

server:
port: 8080
compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json
    min-response-size: 1024
like image 968
Rick GZ Avatar asked Sep 21 '16 17:09

Rick GZ


2 Answers

I added spring-boot-starter-data-jest library to build script, build.gradle:

-    compile "org.springframework.boot:spring-boot-starter-data-elasticsearch"
+    compile "com.github.vanroy:spring-boot-starter-data-jest:2.2.0.RELEASE"

Added exclude for ElasticsearchAutoConfiguration and ElasticsearchDataAutoConfiguration in application class App.java:

@ComponentScan
+@EnableAutoConfiguration(exclude = {
+    ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class })
@EnableConfigurationProperties({ JHipsterProperties.class, LiquibaseProperties.class })
public class App {

And changed:

import org.elasticsearch.client.Client;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.vanroy.springdata.jest.JestElasticsearchTemplate;
+import com.github.vanroy.springdata.jest.mapper.DefaultJestResultsMapper;
+import io.searchbox.client.JestClient;

@Configuration
public class ElasticSearchConfiguration {

  @Bean
-    public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
-        return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build()));
+    public JestElasticsearchTemplate elasticsearchTemplate(JestClient client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
+        return new JestElasticsearchTemplate(client, new DefaultJestResultsMapper(
+                new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())));
  }

Then I added configuraiton parameters, file application.yml:

+    data:
+        elasticsearch:
+            properties:
+                path:
+                  home: target/elasticsearch
+                transport:
+                  tcp:
+                      connect_timeout: 120s
        jest:
+            readTimeout: 10000
             uri: ${SEARCHBOX_SSL_URL}
like image 112
Valentyn Kolesnikov Avatar answered Nov 01 '22 14:11

Valentyn Kolesnikov


This works for me:

Type in console heroku config:get BONSAI_URL -a YOUR_HEROKU APP NAME;

You will get something like this:

https://xaawlsdv2z:[email protected]

in application-prod.yml:

data:
        elasticsearch:
            jest:
                uris: https://jasm3ne-1113487.eu-west-1.bonsaisearch.net:443
                read-timeout: 10000
                username: xaawlsdv2z
                password: dvt345cl1dk
like image 1
Wiktor Syrotin Avatar answered Nov 01 '22 14:11

Wiktor Syrotin