java 连接 Elasticsearch 使用 RestHighLevelClient 进行插入、删除、修改、查询数据

本文介绍了如何使用Java的RestHighLevelClient连接Elasticsearch,进行数据的插入、删除、修改和查询操作,包括单条和多条查询。详细步骤包括设置依赖、配置、执行各种CRUD操作。
摘要由CSDN通过智能技术生成

依赖

<!-- elasticsearch-rest-client -->
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-client</artifactId>
    <version>7.13.3</version>
</dependency>
<!-- elasticsearch-rest-high-level-client -->
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>7.13.3</version>
</dependency>

配置

@Configuration
public class ESConfig {
   

    @Bean
    public RestHighLevelClient getRestHighLevelClient(){
   
        HttpHost http1 = new HttpHost("127.0.0.1", 9200, "http");
        HttpHost http2 = new HttpHost("127.0.0.1", 9201, "http");
        RestClientBuilder restClientBuilder = RestClient.builder(http1, http2);
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
        return restHighLevelClient;
    }

}
@Autowired
private RestHighLevelClient restHighLevelClient;

插入或更新数据

public void insertOrUpdateData() throws IOException {
   
    HashMap<String, String> map = new HashMap<>();
    map.put("name"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值