Elasticsearch核心概念

elasticsearch是面向文档的,关系型数据库和elasticsearch客观的对比!

数据库索引 (indices)
表(tables)types
行(rows)documents
字段(columns)fields
Relationnal DBelasticsearch

analyze:分词器

analyzer: ik_smart ik_max_word 两种分词选择

ik_smart: 最粗粒度分词器,ik_max_word: 最细粒度分词器

基本的Restful操作:

methodurl地址描述
PUTlocalhost:9200/索引名称/类型名称/文档id创建文档(自定义id)
POSTlocalhost:9200/索引名称/类型名称/创建文档(随机id)
POSTlocalhost:9200/索引名称/类型名称/文档id/_update修改文档
DELETElocalhost:9200/索引名称/类型名称/文档id删除文档
GETlocalhost:9200/索引名称/类型名称/文档id阅读指定文档
GETlocalhost:9200/索引名称/类型名称/_search查询所有数据

简单查询操作:

GET /test1/type1/_search?request_cache=false
{
"query": {
 "match": {
    "name":{
      "query": "马云",
      "analyzer": "ik_smart"
    }
 }
},
"from": 0,
"size": 1
}

其中from 和 size正好是sql中的limit的第一个和第二个参数

然后

GET /test1/type1/_search?request_cache=false
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "age": "12"
          }
        },
        {
          "match": {
            "name": "马超"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 3
}

bool,must命令

用于过滤条件eq

如果把must改成should那就是只要满足其中一个条件即可查询出来

默认的分词器:keyword(整体),standard(拆分)

高亮显示:highlight

SpringBoot整合ES

导入依赖:
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

然后在代码中

/**
     * 创建索引
     */
    @Test
    void createIndex() throws IOException {
        // 创建索引请求
        CreateIndexRequest request = new CreateIndexRequest("snkkka1");
        // 发送请求得到响应
        CreateIndexResponse response = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
        System.out.println(response);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值