Trying to store and get some data using ElasticSearch

只谈情不闲聊 提交于 2020-08-10 01:12:51

问题


I have this small configuration using ElasticSearch, but since i want to store some data , i am getting the error below: with repository.save(new FileProperty("12dW", 123.123, "hii")); P.S. the elasticSearch is runing on the port 9200 using docker

    Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.elasticsearch.UncategorizedElasticsearchException: Elasticsearch exception [type=illegal_argument_exception, reason=request [/index/_refresh] contains unrecognized parameter: [ignore_throttled]]; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=request [/index/_refresh] contains unrecognized parameter: [ignore_throttled]]]] with root cause

org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=illegal_argument_exception, reason=request [/index/_refresh] contains unrecognized parameter: [ignore_throttled]]

FileRepository.java

@Repository

public interface FileRepository extends ElasticsearchRepository<FileProperty, String> {

    List<FileProperty> findByName(String filename);

}

FileProperty.java

@Document(indexName = "index", type = "user", shards = 2)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FileProperty {
    @Id
    private String id;
    private double filesize;
    private String name;
}

Config.java

public class Config {

@Bean
public RestHighLevelClient client() {
    ClientConfiguration clientConfiguration
            = ClientConfiguration.builder()
            .connectedTo("localhost:9200")
            .build();

    return RestClients.create(clientConfiguration).rest();
}

@Bean
public ElasticsearchOperations elasticsearchTemplate() {
    return new ElasticsearchRestTemplate(client());
}

}

application.yml

      # Local Elasticsearch config
        spring.data.elasticsearch.repositories.enabled=true
        spring.data.elasticsearch.cluster-nodes=localhost:9200
        spring.data.elasticsearch.cluster-name=elasticsearch
        
        elasticsearch.index.name=index
        elasticsearch.user.type=user

回答1:


It seems you are using an Elasticsearch client lib in version 6 or 7 to access an Elasticsearch 5 cluster.

Please check the compatibility matrix which versions of Spring Data Elasticsearch and Spring Boot to use with which version of Elasticsearch.

Another thing: You should use

spring.elasticsearch.server=localhost:9200

to configure where your Elasticsearch cluster is running and remove these two lines:

spring.data.elasticsearch.cluster-nodes=localhost:9200
spring.data.elasticsearch.cluster-name=elasticsearch

Theses are configuration values for the transport client and Spring Boot will configure one if these properties are set.



来源:https://stackoverflow.com/questions/63175882/trying-to-store-and-get-some-data-using-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!