在Jhipster - Heroku中设置盆景弹性搜索

时间:2016-09-21 17:43:50

标签: spring heroku elasticsearch jhipster bonsai-elasticsearch

在部署到Heroku我的Jhipster应用程序之后,我想使用云弹性搜索(Bonsai)和JHipster。盆景提供以下env变量:

$BONSAI_URL 

如何在application-prod.yml中正确添加? 我一直在阅读文档,并尝试将其设置为集群节点值和主机。但我有点失落。任何提示都非常受欢迎。

应用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: noreply@app.com

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

2 个答案:

答案 0 :(得分:6)

我添加了spring-boot-starter-data-jest库来构建脚本build.gradle:

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

在应用程序类App.java中添加了ElasticsearchAutoConfiguration和ElasticsearchDataAutoConfiguration的排除:

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

改变了:

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())));
  }

然后我添加了configuraiton参数,文件application.yml

+    data:
+        elasticsearch:
+            properties:
+                path:
+                  home: target/elasticsearch
+                transport:
+                  tcp:
+                      connect_timeout: 120s
        jest:
+            readTimeout: 10000
             uri: ${SEARCHBOX_SSL_URL}

答案 1 :(得分:0)

这项工作对我来说:

输入控制台heroku config:get BONSAI_URL -a YOUR_HEROKU APP NAME;

你会得到这样的东西:

https://xaawlsdv2z:dvt345cl1dk@jasm3ne-1113487.eu-west-1.bonsaisearch.net
application-prod.yml中的

data:
        elasticsearch:
            jest:
                uris: https://jasm3ne-1113487.eu-west-1.bonsaisearch.net:443
                read-timeout: 10000
                username: xaawlsdv2z
                password: dvt345cl1dk