Elasticsearch之前整理的一些知识

1 基础

index -> 数据库
type -> 表
document -> 行
field -> 列
-------------------------------------------------------------------
字段属性
type
    String
        text -> 可分词,不能聚合
        keyword -> 可聚合,不能分词
    数值类型
        long.integer.short.byte.double.float.half_float.scaled_float
    
index
    true -> 会被索引,默认true
    false -> 不会被索引,如设置图片
-------------------------------------------------------------------
创建数据库 a1 分片5 副本1
PUT a1
{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1
  }
}

查看数据库 a1
GET a1

查看所有数据库
GET *

删除数据库 a1
DELETE a1

2

//在 a1 数据库中建表 student
//建立字段 name(类型text 指定分词) age(类型integer)
PUT a1/_mapping/student
{
  "properties": {
    "name": {
      "type": "text",
      "analyzer": "ik_max_word"
    },
    "age": {
      "type": "integer"
    }
  }
}

查看 a1 数据库中建立的表解构
GET a1/_mapping

往表中添加数据
POST a1/student
{
  "name":"小米手机",
  "age":11
}

查看 a1 数据库的全部数据
_source -> 查询到的数据
_id -> 文档的唯一标识
GET a1/_search
{
    "query":{
        "match_all": {}
    }
}

自定义 _id 为2 的数据
POST a1/student/2
{
  "name":"大米手机",
  "age":22
}

如果添加字段 address 不存在就会自动创建
POST a1/student/3
{
  "name":"小米电视4K",
  "age":33,
  "address":"安徽阜阳晶宫大酒店101"
}

修改数据如果对应 id 存在则删除之前的再添加 不存在则添加
PUT a1/student/4
{
  "name":"小米电脑",
  "age":44
}

删除id=4的文档
DELETE a1/student/4

3

4

5

6

7

8

9

猜你喜欢

转载自www.cnblogs.com/taopanfeng/p/11684557.html
今日推荐