Elasticsearch的初步学习

944 阅读1分钟

前言:

全文以elasticsearch6.*为例,主要是公司业务上有使用。

安装有ik_max_word分词器。

索引(indices)--------------------------------Databases 数据库

  类型(type-----------------------------Table 数据表

     文档(Document)----------------Row 行

       字段(Field)-------------------Columns 列 

image-20220624154118128

倒排和正排:

image-20220624154419606

本文可以配合着这个elasticsearch食用ElasticSearch进阶:一文全览各种ES查询在Java中的实现 - 腾讯云开发者社区-腾讯云 (tencent.com)

【尚硅谷】ElasticSearch教程入门到精通(基于ELK技术栈elasticsearch 7.8.x版本)_哔哩哔哩_bilibili

img

Mysql中的一行数据,在es中的体现:

{
  "_index" : "person",
  "_type" : "_doc",
  "_id" : "4",
  "_score" : 1.0,
  "_source" : {
    "address" : "峨眉山",
    "modifyTime" : "2021-06-29 19:46:25",
    "createTime" : "2021-05-14 11:37:07",
    "sect" : "峨嵋派",
    "sex" : "男",
    "skill" : "降龙十八掌",
    "name" : "宋青书",
    "id" : 4,
    "power" : 50,
    "age" : 21
  }
}

简单梳理了一下ES JavaAPI的相关体系,感兴趣的可以自己研读一下源码

img

常用的请求:

前置ip:

http://ip

这里以此为例

index----es_learning

type----product

查看索引的properties等信息

/es_learning

image-20220629000030773

查看全部hits

/es_learning/_search

image-20220629000011422

查看全部索引信息

/_cat/indices?v

image-20220628235951711

查看集群健康情况

/_cat/health?v

image-20220628235932214

分词器测试

/_analyze

image-20220628235848034

对index简单操作(springboot)

创建索引:三种方法

image-20220628235658599

删除索引:

image-20220628235757408

对document简单操作(springboot)

删除和保存单个:

image-20220628234703801

批量存储和获取全部:

image-20220628234609977

多条件查询:注释是一些是一些小解释。

image-20220628234847796

多条件查询拓展:

image-20220628235149069

配套方法:json处理,构造高亮(有略),构造多条件查询

image-20220628235218644

聚合查询:

image-20220628235317737

配套方法:取前n个聚合数据,取出buckets中的数据。

image-20220628235336068

END

回过头来看,发现其实我还有很多需要学习的。es挺多东西的。