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.

1
  • This works for me when I add @Setting(settingPath="/") to the Domain entity. Commented May 9, 2014 at 9:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.