Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 集成Spring boot和弹性搜索的最佳方法_Java_Spring_Spring Boot_Maven_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,Spring,Spring Boot,Maven,elasticsearch" /> elasticsearch,Java,Spring,Spring Boot,Maven,elasticsearch" />

Java 集成Spring boot和弹性搜索的最佳方法

Java 集成Spring boot和弹性搜索的最佳方法,java,spring,spring-boot,maven,elasticsearch,Java,Spring,Spring Boot,Maven,elasticsearch,我不熟悉弹性搜索。我们正在构建一个带有弹性搜索的Spring引导应用程序 目前,我们一定会使用SpringBoot2.1.3.RELEASE,但我们可以使用最新的稳定弹性搜索版本 做了一些研发,发现以下两个依赖项与弹性搜索集成 1. elasticsearch-rest-high-level-client 2. spring-boot-starter-data-elasticsearch 可能还有其他方法将Spring boot与弹性搜索集成在一起 1. elasticsearch-rest-

我不熟悉弹性搜索。我们正在构建一个带有弹性搜索的Spring引导应用程序

目前,我们一定会使用SpringBoot2.1.3.RELEASE,但我们可以使用最新的稳定弹性搜索版本

做了一些研发,发现以下两个依赖项与弹性搜索集成

1. elasticsearch-rest-high-level-client
2. spring-boot-starter-data-elasticsearch
可能还有其他方法将Spring boot与弹性搜索集成在一起

1. elasticsearch-rest-high-level-client
2. spring-boot-starter-data-elasticsearch
有没有人能帮助确定将Spring boot与弹性搜索集成的最佳方式?


根据以上提供的Spring boot版本,我应该使用哪个版本的Elastic search?

关于Elastic search版本,请访问此网站:

对于将Elasticsearch与SpringBoot一起使用,我们包括三个依赖项:

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.2.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>6.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
一旦创建了客户机,惟一剩下的就是执行CRUD操作

  @Autowired
  ElasticClientService client;

  public void save(Object object, String id, String type, String indexName) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, Object> objectMap = objectMapper.convertValue(object, Map.class);
    IndexRequest indexRequest = new IndexRequest(indexName, type, id);
    indexRequest.source(objectMap);
    IndexResponse response = client.elasticsearchClient().index(indexRequest);
  }

  public void deleteById(String id, String type, String indexName) throws IOException {
    DeleteRequest request = new DeleteRequest(indexName, type, id);
    DeleteResponse deleteResponse = client.elasticsearchClient().delete(request);
  }

@Autowired
ElasticClientService客户端;
公共无效保存(对象对象、字符串id、字符串类型、字符串索引名)引发IOException{
ObjectMapper ObjectMapper=新的ObjectMapper();
MapObjectMap=objectMapper.convertValue(对象,Map.class);
IndexRequest IndexRequest=新的IndexRequest(indexName、类型、id);
源(objectMap);
IndexResponse-response=client.elasticsearchClient().index(indexRequest);
}
public void deleteById(字符串id、字符串类型、字符串索引名)引发IOException{
DeleteRequest=新的DeleteRequest(索引名称、类型、id);
DeleteResponse DeleteResponse=client.elasticsearchClient().delete(请求);
}
以上两个操作在弹性索引中创建一个文档(行),并根据ID从弹性索引中删除一个文档(行)

有关更多参考信息,请参见:*
*根据需要更改版本


您可以参考进一步的帮助

我有一个用Spring boot 2.1.0.RELEASE和Elasticsearch 6.2.2构建的应用程序。确保使用相同的版本。最重要的是pom.xml及其版本。它对我很有效。谢谢你的建议!我不能使用最新版本的弹性搜索吗?如果不是,那么为什么呢?因为data elasticsearch仅支持ES transportclient,它将无法与rest高级客户端(请参见我的第一个示例)一起工作。为了提高性能,我将选择elasticsearch rest高级客户端,如我的第二个示例所示。您也可以将两者结合使用(请参见下面的答案)。当组合使用时,您将使用SpringDataElasticSearch,这样您就可以使用其酷(但有限)的内置查询语言。有关更多compex查询,请使用rest高级客户端。所谓复杂,我指的是分析之类的。我一定要用Spring boot!谢谢你的回答,我发现最好只使用“高级Rest客户端”。如果我使用高级rest客户端进行集成,我可以将“elasticsearch-7.7.1”与我的“Spring Boot 2.1.3.RELEASE”一起使用吗?