ArisRe82
ArisRe82

Reputation: 535

How to set the data directory of ElasticSearch with Spring Boot

My problem is similar to [1] I have a spring boot appplication where I save some document in elasticsearch. The index is created in a data dir in the current directory each time. I want to change this default path to a given one. How can I do that? A such a simple task takes hours to find it out.

I tried many things:

  1. @Setting(setting="/data/elasticsearch")
  2. In an elasticseacrh.properties and application.properties file:
    1. path.data
    2. spring.data.elasticsearch.path.data

Without any luck.

Upvotes: 6

Views: 4116

Answers (3)

Amer Qarabsa
Amer Qarabsa

Reputation: 6574

I just ran into this issue and none of the answers provided solved it , the accept answer got the wrong property which is

 spring.data.elasticsearch.properties.path.data=/path/to/data

not

 spring.data.elasticsearch.properties.data.path=/path/to/data

Though with this value you will have a problem because you are writing into the root of your machine ( a mac in my case) which needs an access rights which I cannot provide so the elasticsearch template will fail to start, instead you need to set the value to

spring.data.elasticsearch.properties.path.data=path/to/data

This will create the path from the context of your application which is the root directory of your project which the application already has rights to write to it

Upvotes: 0

Raffael Schmid
Raffael Schmid

Reputation: 339

For me (Grails / Spring Boot 1.3.3) the following configuration works better:

spring.data.elasticsearch.properties.path.data=/path/to/data
spring.data.elasticsearch.properties.path.logs=/path/to/logs

Upvotes: 4

ArisRe82
ArisRe82

Reputation: 535

  1. Adding the path with the configuration file in my application class:

    @Setting(settingPath = "/home/topic/src/main/resources/elasticsearch.properties")
    
  2. Set the path.data property in the file:

    path.data=/Users/mimis/Desktop/data
    

Did the trick.

Update:
With Spring Boot 1.3.0 we can add any Elasticsearch property in the application properties files by using the spring.data.elasticsearch.properties.* prefix. For example:

spring.data.elasticsearch.properties.data.path=/path/to/data

Upvotes: 5

Related Questions