簡體   English   中英

將springBoot與elasticsearch 2.x結合使用

[英]Combine springBoot with elasticsearch 2.x

我嘗試使用spring boot 1.3.3來實現與elasticsearch進行通信的項目。 在網上進行了多次搜索之后,我發現spring-boot-starter-data-elasticsearch在我的情況下並不好,因為它使用Elasticsearch 1.5並且我必須使用Elasticsearch 2.2仍然有希望使用spring boot?

當然,您可以將Spring Boot與Elasticsearch 2.x一起使用。 我正在使用它。 這是我的gradle.build的摘錄。

apply plugin: 'spring-boot'

buildscript {
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
    }
}

dependencies {
    // Elasticsearch
    compile ("org.elasticsearch:elasticsearch:2.1.1")

    // Spring Boot
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-web")
    ...
}
...

如果它不適合您的需要,請不要使用spring-boot-starter-data-elasticsearch。

如果需要,可以在使用最新版本更新spring-boot-starter后返回並更新依賴項。 對於Elasticsearch 2.2.0版本,目前有一個2.0.0.RC1版本的spring-data-elasticsearch,因此可以合理地假設spring-boot-starter也會很快更新。

希望這可以幫助。

只有spring-data-elasticsearch子項目與Elasticsearch相關聯。 順便說一句,恕我直言,這種集成真的很糟糕,因為他們試圖將非常靈活的Elasticsearch API適用於非常有限的接口。 如果你想將Spring Boot用於微服務基礎設施和其他東西,只需將它與適當版本的elasticsearch客戶端一起使用,不要打擾spring-boot-starter-data-elasticsearch。

我們使用https://github.com/searchbox-io/Jest成功使用Spring Boot。 以前我們嘗試使用spring-data-elasticsearch但是它與sping-data-mongodb一起使用起來並不好用。 然后我們搬到了JEST,再也沒有回頭。

只需添加

compile('io.searchbox:jest:2.0.2')

gradle配置文件。 JEST有大量的測試,您可以在其中找到所有可能的用例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM