简体   繁体   中英

Trying to store and get some data using ElasticSearch

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM