【问题标题】:Trying to store and get some data using ElasticSearch尝试使用 ElasticSearch 存储和获取一些数据
【发布时间】:2020-11-20 08:36:46
【问题描述】:

我有这个使用 ElasticSearch 的小配置,但由于我想存储一些数据,我收到以下错误:repository.save(new FileProperty("12dW", 123.123, "hii")); elasticSearch 使用 docker 在端口 9200 上运行

    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);

}

文件属性.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

公共类配置{

@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

【问题讨论】:

    标签: java spring-boot elasticsearch gradle spring-data-elasticsearch


    【解决方案1】:

    您似乎正在使用版本 6 或 7 中的 Elasticsearch 客户端库来访问 Elasticsearch 5 集群。

    请查看compatibility matrix 哪个版本的 Spring Data Elasticsearch 和 Spring Boot 与哪个版本的 Elasticsearch 一起使用。

    另一件事:你应该使用

    spring.elasticsearch.server=localhost:9200
    

    配置您的 Elasticsearch 集群的运行位置并删除这两行:

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

    这些是传输客户端的配置值,如果设置了这些属性,Spring Boot 将配置一个。

    【讨论】:

    • 明天我会试试你的解决方案。我将删除提到的行并在 gradle 中设置 2.3.x 上的 springboot 和 7.6.2 上的 elasticsearch 版本,这样可以吗?如果一切正常,我会接受你的解决方案。
    • 如果您使用的 Elasticsearch 集群没有匹配的版本,这将不起作用。您使用的是哪个版本的 Elasticsearch?
    • 我使用的是版本 7.6.2。是的,我警告说集群不匹配。请问你怎么解决这个问题
    • 如果次要版本中的版本不同,则很有可能它可以正常工作。至少在 ES 7 中,我不知道 ES 在次要版本更改之间发生了重大更改
    猜你喜欢
    • 2016-02-10
    • 2019-12-17
    • 2019-12-10
    • 1970-01-01
    • 2021-04-25
    • 2013-12-31
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    相关资源
    最近更新 更多