如何使用Spring Boot设置ElasticSearch的数据目录

Ari*_*e82 6 elasticsearch spring-boot

我的问题类似于[1] 我有一个spring boot appplication,我在elasticsearch中保存了一些文档.每次在当前目录中的数据目录中创建索引.我想将此默认路径更改为给定的路径.我怎样才能做到这一点?这么简单的任务需要几个小时才能找到它.

我尝试了很多东西:

  1. @Setting(setting="/data/elasticsearch")
  2. 在elasticseacrh.properties和application.properties文件中:
    1. path.data
    2. spring.data.elasticsearch.path.data

没有运气.

Ari*_*e82 5

  1. 在我的应用程序类中添加配置文件的路径:

    @Setting(settingPath = "/home/topic/src/main/resources/elasticsearch.properties")
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在文件中设置path.data属性:

    path.data=/Users/mimis/Desktop/data
    
    Run Code Online (Sandbox Code Playgroud)

诀窍.

更新:
使用Spring Boot 1.3.0,我们可以使用spring.data.elasticsearch.properties.*前缀在应用程序属性文件中添加任何Elasticsearch属性.例如:

spring.data.elasticsearch.properties.data.path=/path/to/data
Run Code Online (Sandbox Code Playgroud)

  • 目前我使用的是Spring boot 2.6.在我位于资源文件夹中的应用程序/属性文件中,我有设置spring.data.elasticsearch.properties.path.data并且它可以工作 (2认同)