ES | Mysql |
---|---|
Index(索引) | Database(数据库) |
Type(类型:es7+已删除) | Table(表) |
Documents(文档) | Row(行) |
Field(字段) | Column(列) |
GET /_cat/health?help
GET /_search
{"query": {"match_all": {}}
}
GET /_cat/health?v
GET /_cat/nodes?v
# 第一种
GET /_cat/indices?v
# 第二种(简化)
GET /_cat/indices?v&h=health,status,index
PUT /book
DELETE /book
列出全部索引信息
GET /_cat/indices?v
先创建索引
PUT /book
{"settings": {"number_of_shards": 5,"number_of_replicas": 1},"mappings": {"dynamic": "strict", # 插入数据时,如果遇到不存在的字段,不新增字段,直接报错"properties": {"title": {"type": "text","index": true},"publisher": {"type": "keyword","index": true},"page": {"type": "text","index": false},"my_vector": {"type": "dense_vector","dims": 2}}}
}
ps:
POST /book/_doc/1
{ "title":"历史上的今天","created":"2018-12-25"
}
POST /book/_doc
{ "title":"历史上的今天","created":"2018-12-25"
}
根据id删除
DELETE /book/_doc/1
# title 和 created 全部更新
PUT /book/_doc/1
{ "title":"历史上的今天2","created":"2021-01-01"
}
# 仅更新 created
POST /book/_update/1
{ "doc": {"created":"2021-01-01" }
}
查询 book 索引下 _id 为 1 的文档
# 写法1
GET /book/_doc/1 # 写法2
GET /book/_search
{"query": {"match": {"_id": 1}}
}
查询 book 索引下的全部文档【默认返回前10000条】
# 写法1
GET /book/_search# 写法2
GET /book/_search
{"query": {"match_all": {}}
}# 写法3
GET /book/_doc/_search
查询 book 索引下的文档总数
GET /book/_count
GET /book/_search
{"query": {"match": {"title": "历史上的今天"}}
}
ps:
查询 book 索引下满足 title 包含 历史上的今天 的数据
# 推荐写法
GET /book/_search
{"query": {"match_phrase": {"title": "历史上的今天"}}
}# 不推荐写法
GET /book/_search?q=title:历史上的今天
查询 book 索引下满足 title 包含 历史上的今天 and created=2018-12-20 的数据
GET /book/_search
{"query": {"bool": {"must": [{"match_phrase": {"title": "历史上的今天"}},{"match_phrase": {"created": "2018-12-20"}}]}}
}
查询 book 索引下满足 title 包含 历史上的今天 or title 包含 历史上的今天2 的数据
GET /book/_search
{"query": {"bool": {"should": [{"match_phrase": {"title": "历史上的今天"}},{"match_phrase": {"title": "历史上的今天2"}}]}}
}
查询 book 索引中满足 title 包含 “历史” 的数据,并将检索结果中的历史俩字用<em>标签包裹
GET /book/_search
{"query": {"match_phrase": {"title": "历史"}},"highlight": {"fields": {"title": {}}}
}
ps:
查询 book 索引下满足 price > 100 的数据
GET /book/_search
{"query": {"bool": {"filter": {"range": {"price": {"gt": 100.00}}}}}
}
ps:
分页查询 book 索引下的全部数据,查询第1页,每页2条数据
GET /book/_search
{"from": 0,"size": 2
}
查询 book 索引下的全部数据,仅返回 title 字段
GET /book/_search
{"_source": ["title"]
}
查询 book 索引下的全部数据,以创建时间降序排序
GET /book/_search
{"sort": {"created": {"order": "desc"}}
}
ps:
对 book 索引下的 title 字段进行聚合查询
GET /book/_search
{"aggs": {"title_group": {"terms": {"field": "title.keyword","size": 10 }}},"size": 0
}
ps:
对 book 索引下的 price 字段求平均值
GET /book/_search
{"aggs": {"price_avg": {"avg": {"field": "price" }}},"size": 0
}
ps:
本文发布于:2024-02-02 15:53:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686040544838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |