尝试使用ElasticSearch存储和获取一些数据。

huangapple go评论131阅读模式
英文:

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

  1. @Repository
  2. public interface FileRepository extends ElasticsearchRepository<FileProperty, String> {
  3. List<FileProperty> findByName(String filename);
  4. }

FileProperty.java

  1. @Document(indexName = "index", type = "user", shards = 2)
  2. @Data
  3. @AllArgsConstructor
  4. @NoArgsConstructor
  5. public class FileProperty {
  6. @Id
  7. private String id;
  8. private double filesize;
  9. private String name;
  10. }

Config.java

  1. public class Config {
  2. @Bean
  3. public RestHighLevelClient client() {
  4. ClientConfiguration clientConfiguration
  5. = ClientConfiguration.builder()
  6. .connectedTo("localhost:9200")
  7. .build();
  8. return RestClients.create(clientConfiguration).rest();
  9. }
  10. @Bean
  11. public ElasticsearchOperations elasticsearchTemplate() {
  12. return new ElasticsearchRestTemplate(client());
  13. }
  14. }

application.yml

  1. # 本地Elasticsearch配置
  2. spring.data.elasticsearch.repositories.enabled=true
  3. spring.data.elasticsearch.cluster-nodes=localhost:9200
  4. spring.data.elasticsearch.cluster-name=elasticsearch
  5. elasticsearch.index.name=index
  6. 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(&quot;12dW&quot;, 123.123, &quot;hii&quot;)); P.S. the elasticSearch is runing on the port 9200 using docker

  1. 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
  2. org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=illegal_argument_exception, reason=request [/index/_refresh] contains unrecognized parameter: [ignore_throttled]]

> FileRepository.java

  1. @Repository
  2. public interface FileRepository extends ElasticsearchRepository&lt;FileProperty, String&gt; {
  3. List&lt;FileProperty&gt; findByName(String filename);
  4. }

> FileProperty.java

  1. @Document(indexName = &quot;index&quot;, type = &quot;user&quot;, shards = 2)
  2. @Data
  3. @AllArgsConstructor
  4. @NoArgsConstructor
  5. public class FileProperty {
  6. @Id
  7. private String id;
  8. private double filesize;
  9. private String name;
  10. }

> Config.java

public class Config {

  1. @Bean
  2. public RestHighLevelClient client() {
  3. ClientConfiguration clientConfiguration
  4. = ClientConfiguration.builder()
  5. .connectedTo(&quot;localhost:9200&quot;)
  6. .build();
  7. return RestClients.create(clientConfiguration).rest();
  8. }
  9. @Bean
  10. public ElasticsearchOperations elasticsearchTemplate() {
  11. return new ElasticsearchRestTemplate(client());
  12. }

}

> application.yml

  1. # Local Elasticsearch config
  2. spring.data.elasticsearch.repositories.enabled=true
  3. spring.data.elasticsearch.cluster-nodes=localhost:9200
  4. spring.data.elasticsearch.cluster-name=elasticsearch
  5. elasticsearch.index.name=index
  6. elasticsearch.user.type=user

答案1

得分: 0

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

请检查兼容性矩阵,以确定Spring Data Elasticsearch和Spring Boot与Elasticsearch的哪个版本搭配使用。

另一件事:您应该使用以下配置来指定Elasticsearch集群的运行位置,并移除以下两行配置:

  1. 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

  1. spring.elasticsearch.server=localhost:9200

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

  1. spring.data.elasticsearch.cluster-nodes=localhost:9200
  2. 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.

huangapple
  • 本文由 发表于 2020年7月30日 22:57:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63175882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定