更新一下用到的所有es的基础操作
ES操作命令集
基础操作
获取版本信息
GET /
查看节点信息
GET _nodes/stats?pretty
查看索引模板
GET /_template/pm_perf_itemrawinfo
创建索引
PUT /索引名
{
"settings": {
"index.max_result_window": "10000"
},
"mappings": {
"properties": {
"字段1": {
"type": "keyword"
},
"字段2": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
创建索引模板
POST /_template/模板名
{
"template" : "模板匹配名称*",
"settings": {
"index.max_result_window": "10000"
},
"mappings": {
"properties": {
"字段1": {
"type": "keyword"
},
"字段2": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
删除索引
DELETE 索引名
查看索引映射
查看所有
GET /_mapping?pretty=true
查看指定
GET 索引名/_mapping
查看模板
查看所有
GET _cat/templates
查看指定模板
GET /_template/模板名
查看索引分片
GET 索引名/_search_shards
查看索引配置
GET /索引名/_settings
更改基础配置
PUT /_cluster/settings
{
"transient": {
"cluster": {
"max_shards_per_node":10000
}
}
}
数据操作
新增数据—bulk语句(批量)
POST /_bulk?pretty
{"index":{"_index":"索引名","_type":"_doc","_id":"主键"}}
{"字段1":"值1","字段2":"值2"
}
新增数据
POST 索引名/_doc/主键
{
"字段1": "值1",
"字段2": "值2"
}
数据迁移
POST /_reindex
{
"source": {
"index": "源索引"
},
"dest": {
"index": "目的索引"
}
}
执行sql语句
支持简单sql,不支持嵌套(需安装sql插件,7.0之后版本自动集成)
POST /_sql?format=json
{
"query": "待执行sql"
}
dsl语句-查询
POST 索引名称/_search
{
"query": {
"bool": {
"must": [
查询内容
]
}
},"size": 20000000,
"sort": [
{
"待排序字段": {
"order": "asc"
}
}
]
}
dsl语句-删除
POST 索引名称/_delete_by_query
{
"query": {
"bool": {
"must": [
查询内容
]
}
},"size": 20000000
}
游标操作
POST /_search/scroll
{
"scroll": "3m",
"scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAknmEWZU8wTWVuYi1UaEtERmIxUVZsb0ZIUQ=="
}
DSL复杂查询
匹配多字段
POST /索引名/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"字段1": [
"值1",
"值2"
]
}
}
]
}
}
}
范围查询
POST /索引名/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"OPERATOR_TIME": {
"gte": "2020-09-25 00:00:00",
"lte": "2020-10-30 23:00:00"
}
}
}
]
}
}
}
模糊匹配
POST /索引名/_search
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"OPERATOR_CMD": {
"value": "*同步*"
}
}
}
]
}
}
}
排序
跟在query后
"sort": [
{
"RECORD_TIME": {
"order": "desc"
}
}
]
from,size
"from": 0,
"size": 1000