英文:
Trying to store and get some data using ElasticSearch
问题
我有一个使用ElasticSearch的小配置,但由于我想要存储一些数据,所以出现了以下错误:使用repository.save(new FileProperty("12dW", 123.123, "hii"));
P.S. ElasticSearch正在端口9200上使用Docker运行。
Servlet.service()的servlet [dispatcherServlet]在路径为空的上下文中抛出异常[请求处理失败;嵌套异常是org.springframework.data.elasticsearch.UncategorizedElasticsearchException:Elasticsearch异常[type=illegal_argument_exception,reason=request [/index/_refresh]包含无法识别的参数:[ignore_throttled]];嵌套异常是ElasticsearchStatusException[Elasticsearch异常[type=illegal_argument_exception,reason=request [/index/_refresh]包含无法识别的参数:[ignore_throttled]]]]根本原因是
org.elasticsearch.ElasticsearchStatusException:Elasticsearch异常[type=illegal_argument_exception,reason=request [/index/_refresh]包含无法识别的参数:[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
# 本地Elasticsearch配置
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
英文:
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
得分: 0
似乎您正在使用版本为6或7的Elasticsearch客户端库来访问Elasticsearch 5集群。
请检查兼容性矩阵,以确定Spring Data Elasticsearch和Spring Boot与Elasticsearch的哪个版本搭配使用。
另一件事:您应该使用以下配置来指定Elasticsearch集群的运行位置,并移除以下两行配置:
spring.elasticsearch.server=localhost:9200
以下两行配置是传输客户端的配置值,如果设置了这些属性,Spring Boot将自动配置传输客户端。
请按照上述建议进行操作。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论