Easton's Blog Easton's Blog
首页
  • 编程语言

    • Python
  • 框架

    • Django
  • Mdn (opens new window)
  • HTML
  • CSS
  • JavaScript
  • Mysql
  • PostgreSQL
  • Elasticsearch
  • MongoDB
  • Redis
  • 服务器命令
  • Docker
  • GIT
  • 摄影
  • 草稿
  • 归类方式

    • 分类
    • 标签
    • 归档
  • 关于博客

    • 博客教程
    • 友情链接
    • 关于
导航站
GitHub (opens new window)

Easton Yang

爱生活😊爱学习
首页
  • 编程语言

    • Python
  • 框架

    • Django
  • Mdn (opens new window)
  • HTML
  • CSS
  • JavaScript
  • Mysql
  • PostgreSQL
  • Elasticsearch
  • MongoDB
  • Redis
  • 服务器命令
  • Docker
  • GIT
  • 摄影
  • 草稿
  • 归类方式

    • 分类
    • 标签
    • 归档
  • 关于博客

    • 博客教程
    • 友情链接
    • 关于
导航站
GitHub (opens new window)
  • Mysql

  • PostgreSQL

  • ES

    • es基本命令
      • 1、案例数据
      • 2、基本命令
        • 查看 es 基本信息
        • 查看当前节点的所有 Index
        • 列出每个 Index 所包含的 Type
        • 新建 index
        • 删除 index
        • 新增一条数据
        • 使用 PUT 新增/更新数据
        • 使用 id 查看记录
        • 删除记录
        • 查询所有记录
        • 排序
        • 使用 json 文件插入数据
        • 查看数据条数
        • 查看 es 健康状况
    • es全文搜索
    • mapping
    • 聚合
  • MongoDB

  • Redis

  • 数据库
  • ES
eastonyangxu
2023-06-29
目录

es基本命令

Elasticsearch7.6 中文文档 (opens new window)

# 1、案例数据

# 1、单独添加
curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/accounts/person/1' -d '{"user": "marray", "title": "doctor", "desc": "I’m a doctor"}'
curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/accounts/person/2' -d '{"user": "tom", "title": "teacher", "desc": "I’m a teacher"}'
curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/accounts/person/3' -d '{"user": "jack", "title": "teacher", "desc": "I’m a teacher"}'
# 2、多条记录添加并指定id,注意每个json需要换行,包括最后一行
curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/accounts/person/_bulk?pretty' -d '
{"create": {"_id": 1}}
{"user": "marray", "title": "doctor", "desc": "I’m a doctor"}
{"create": {"_id": 2}}
{"user": "tom", "title": "teacher", "desc": "I’m a teacher"}
{"create": {"_id": 3}}
{"user": "jack", "title": "teacher", "desc": "I’m a teacher"}
'
1
2
3
4
5
6
7
8
9
10
11
12
13

# 2、基本命令

# 查看 es 基本信息

curl 'localhost:9200'
1

# 查看当前节点的所有 Index

curl -X GET 'http://localhost:9200/_cat/indices?v'
1

# 列出每个 Index 所包含的 Type

curl 'localhost:9200/_mapping?pretty=true'
1

# 新建 index

curl -X PUT 'localhost:9200/weather'
1

# 删除 index

curl -X DELETE 'localhost:9200/weather'
1

# 新增一条数据

# 在没有创建 index 的时候新增数据会自动创建 index
curl -H 'Content-Type: application/json' -X POST 'localhost:9200/accounts/person' -d '
{"user": "tom", "title": "teacher"}'
1
2
3

# 使用 PUT 新增/更新数据

# 需要指定 id,id 不一定是数字,可以是随意的字符串
curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/accounts/person/1' -d '
{"user": "tom", "title": "teacher"}'
1
2
3

# 使用 id 查看记录

curl 'localhost:9200/accounts/person/1?pretty=true'
1

# 删除记录

curl -X DELETE 'localhost:9200/accounts/person/1'
1

# 查询所有记录

curl 'localhost:9200/accounts/person/_search'
1

# 排序

# 该案例可能报错,但是语法没问题
curl -H 'Content-Type: application/json' 'localhost:9200/accounts/person/_search?pretty' -d '
{"query": {"match_all": {}}, "sort": [{"user": "desc"}]}'
1
2
3

# 使用 json 文件插入数据

点击下载:accounts.json 文件

# 注意 json 文件最后一行需要数据需要换行(最后留一行空行),@后面是绝对路径
curl -H 'Content-Type: application/json' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@/Users/yangxu/Desktop/es/accounts.json"
1
2

# 查看数据条数

curl 'localhost:9200/[index]/_count'
1

# 查看 es 健康状况

curl 'localhost:9200/_cluster/health?pretty'
1
#ES
上次更新: 2023/08/08, 20:00:46
索引
es全文搜索

← 索引 es全文搜索→

最近更新
01
攻略制作要点
07-18
02
摄影主题拍摄
07-18
03
延时摄影剧本
07-18
更多文章>
Theme by Vdoing | Copyright © 2023-2024 Easton Yang | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式