elasticsearch基础知识

索引、文档

索引类似于MySQL的表,一个索引存储一类数据;文档是原数据,存储在索引里,相当于一条MySQL记录。

通过这个API获取索引信息;

 

 

通过这个API来获取具体的文档信息。

 

 

节点、分片

节点可以认为是部署的elasticsearch的实例数,分片类似RocketMQ的broker,一个索引可能把数据分成几个shades存储,有主分片和备用分片。

创建索引的时候可以指定分片,使用GET API可以获取索引分片信息。

 

 

日常API

# 获取索引
GET users

# 查询文档
GET users/_doc/1

# 创建文档,如果存在,则删除原来文档并添加新文档,version + 1
POST users/_doc/1
{
  "user":"Mike",
  "post_date":"2021-10-28T11:07:00",
  "message":"hello world"
}
# 更新文档内容
POST users/_update/1/
{
  "doc":{
      "post_date":"2021-10-28T11:07:00",
      "message":"hello world"
  }

}
# 更新文档内容
PUT users/_doc/1
{
  "user":"test_name"
}

# 多个文档获取
GET _mget
{
  "docs":[
    {"_index":"users","_id":"1"}
    ]  
}

# 输出分词
GET _analyze
{
  "analyzer":"simple",
  "text":"2 The world is the great production of nature "
}

# 使用索引分词
POST users/_analyze
{
  "field":"user",
  "text":"master slaver"
}

# 配置分词器以及filter
POST /_analyze
{
  "tokenizer": "standard",
  "filter": ["lowercase"],
  "text":"The World Champion"
}

 

 

posted @ 2021-11-01 17:19  天目山电鳗  阅读(29)  评论(0编辑  收藏  举报