尝试使用ElasticSearch存储和获取一些数据 [英] Trying to store and get some data using ElasticSearch

查看:1104
本文介绍了尝试使用ElasticSearch存储和获取一些数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ElasticSearch进行了这种小型配置,但是由于我想存储一些数据,因此出现以下错误:repository.save(new FileProperty("12dW", 123.123, "hii")); P.S. elasticSearch正在使用docker在端口9200上运行

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

FileRepository.java

@Repository

public interface FileRepository extends ElasticsearchRepository<FileProperty, String> {

    List<FileProperty> findByName(String filename);

}

FileProperty.java

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

Config.java

公共类Config {

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

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

推荐答案

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

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

请检查兼容性矩阵与哪个版本的Elasticsearch一起使用哪个版本的Spring Data Elasticsearch和Spring Boot.

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

另一件事:您应该使用

spring.elasticsearch.server=localhost:9200

配置Elasticsearch集群的运行位置,并删除以下两行:

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

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

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

这篇关于尝试使用ElasticSearch存储和获取一些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆