2

I am using elasticsearch for my application and this the domain entity

@Document(indexName = "bookstore", type = "book", refreshInterval = "-1")
public class Book {
    @Id
    @Column(name = "ID")
    private Long id;

    @Column(name = "NAME")
    @Field(type=FieldType.String)
    private String name;

    @Column(name = "DESCRIPTION")
    private String description;

    @Column(name = "PRICE")
    private Double price;

This is the config file

@Configuration
@EnableElasticsearchRepositories(basePackages =
"elasticsearch.repo")
public class BookSearchRepositoryTestConfig {

@Bean

public ElasticsearchOperations elasticsearchTemplate() throws IOException {
        return new ElasticsearchTemplate(nodeBuilder()
                .loadConfigSettings(false)
                .local(true)
                .settings(
                ImmutableSettings.settingsBuilder()
                .put("index.store.type", "memory")
                .put("index.number_of_shards", 1)
                .put("index.number_of_replicas", 0).build()
                ).node().client());
}

This settings doesnt work.It use defualt settings and create 5 shards.

I know this can done by using @Document

@Document(indexName = "bookstore", type = "book", shards = 1, replicas = 0, indexStoreType = "memory", refreshInterval = "-1")

or using @Setting

@Setting(settingPath = "/settings/elasticsearch-settings.json")

But I am tring to use the config file and set the properties. Please guide me to solve this issue.

user3615392
  • 91
  • 2
  • 5

1 Answers1

2
@Bean
public ElasticsearchOperations elasticsearchTemplate() throws IOException {

 Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("elasticsearch.yml").build();

        return new ElasticsearchTemplate(nodeBuilder()
                .loadConfigSettings(false)
                .local(true)
                .settings(settings).node().client());
    }

This works.But I had to add @Setting(settingPath="/") to the domain entity.

user3615392
  • 91
  • 2
  • 5