ElastisSearch基础并对其简单的CRUD测试

ElasticSearch主要用于全文检索,适用于各种规模的项目。相比Lucene,ES使用更简便,支持集群和分布式,且操作接口为JSON。本文介绍了如何启动服务器,进行增删改查等基本操作。
摘要由CSDN通过智能技术生成

ElastisSearch --主要用途 做全文检索

最关键的是,ES无论是什么项目,中小型项目还是大型项目都能完美使用起来

为什么要使用ElasticSearch

Lucene 缺点:
使用起来很复杂
Lucene不支持集群

ES:特点:
(1) Es 全文检索框架 使用比lucene更简单
(2) ES支持集群 支持分布式
(3) 支持JSON的操作
(4) 一般大型全文检索都是用ES
(5) 通过Restfull风格来操作ES

ElasticSearch所要导入的包
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>

(1)使用之前需要打开服务器,+写下面的工具类

public static TransportClient getClient() throws Exception {
      TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
              .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));        return client;
  }


(2)然后对其简单的增删改查测试

增加
@Test
public void getCreated() throws UnknownHostException {
   
    TransportClient client = getClient();
    IndexRequestBuilder indexRequestBuilder = client.prepareIndex("crm", "user", "1");
    Map<String,Object> mp = new HashMap();
    mp.put("id",2);
    mp.put("name","kg");
    mp.put("age",18);
    IndexResponse indexResponse = indexRequestBuilder.setSource(mp).get();
    System.out.println(indexResponse
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值