ES常用命令

ES个人常用的一些命令

集群相关信息

#查看所有的cat操作
GET /_cat
#查看集群当前状态:红、黄、绿
GET /_cluster/health
#查看节点信息
GET /_cat/nodes?v 
#查看master节点信息
GET /_cat/master?v
#查看集群详情
GET /_cluster/stats
#查看集群等待任务
GET /_cluster/pending_tasks

索引相关信息

#查看指定索引的全部信息
GET /indextest001
#查看指定索引的配置信息
GET /indextest001/_settings?
#查看指定索引的属性信息
GET /indextest001/_mapping?
#查看索引生命周期
GET /indextest001/_ilm/explain
#列出所有索引详情
GET /_cat/indices?v
#查看指定索引详情
GET /_cat/indices/my-index-000003?v

分片和段相关信息

#查看各索引分片的详细情况
GET /_cat/shards?v
#查看指定索引分片的详细情况
GET /_cat/shards/my-index-000003?v
#修改索引分片数量
PUT /indextest001/_settings
{
    "settings": {
        "number_of_replicas": 0
    }
}
#查看所有index的段信息
GET /_cat/segments?v

文档相关信息

#查看索引的文档数量
GET /_cat/count/career_plan_sku_index_52?v

#查看索引全部文档
GET rollover_test-000001/_search
{
  "query": {
    "match_all": {}
  }
}

#索引增加文档
POST /rollover_test-000001/_doc
{
  "name": "caodewang"
}

#查看分词器分词结果
GET /_analyze
{
    "analyzer": "ik_max_word",
    "text": "博文视点"
}
GET /career_plan_sku_suggest/_analyze
{
    "text": "猫窝宠物窝垫冬季保暖宠物床⼩猫窝猫⽤品",
    "analyzer": "ik_and_pinyin_analyzer"
}

索引别名相关信息

#查看所有index的别名信息
GET /_cat/aliases?v

#根据索引别名查看索引
GET /_cat/aliases/rollover_test_alias

#根据索引查看索引别名
GET indextest001/_alias

#新增索引别名
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "indextest001",
        "alias": "shop"
      }
    }
  ]
}

#删除索引别名
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "indextest001",
        "alias": "shop"
      }
    }
  ]
}

索引生命周期相关信息

#查看集群配置
GET _cluster/settings
#修改生命周期刷新频率配置
PUT _cluster/settings
{
  "persistent": {
    "indices.lifecycle.poll_interval": "10s"
  }
}
#新增滚动生命周期策略
PUT _ilm/policy/rollover_test_policy
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0",
        "actions": {
          "set_priority": {
            "priority": 100
          },
          "rollover": {
            "max_docs": 5
          }
        }
      },
      "warm": {
        "min_age": "0",
        "actions": {
          "set_priority": {
            "priority": 50
          },
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "cold": {
        "min_age": "1d",
        "actions": {
          "set_priority": {
            "priority": 0
          },
          "freeze": {}
      }
      },
      "delete": {
        "min_age": "1d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

#新增索引模板
PUT _template/rollover_test_template
{
  "index_patterns": [
    "rollover_test-*"
  ],
  "settings": {
    "index.lifecycle.name": "rollover_test_policy",
    "index.lifecycle.rollover_alias": "rollover_test_alias",
    "number_of_replicas": 0,
    "number_of_shards": 1
  }
}

#查看索引模板
GET /_template/ilm-history

#使用模板创建索引
PUT rollover_test-000001 
{
  "aliases": {
    "rollover_test_alias":{
      "is_write_index": true 
    }
  }
}
#查看索引生命周期
GET rollover_test-000001/_ilm/explain

一些相关实例操作

#创建索引
PUT indextest001

#删除索引
DELETE indextest001

#查看mapping
GET indextest001/_mapping

#创建mapping
POST indextest001/_mapping
{
    "properties": {
        "title": {
            "type": "text"
        },
        "description": {
            "type": "text",
            "index": "false"
        },
        "price": {
            "type": "double"
        },
        "onSale": {
            "type": "boolean"
        },
        "type": {
            "type": "integer"
        },
        "createDate": {
            "type": "date"
        }
    }
}

#使用DSL语法搜索文档
GET /career_plan_sku_index_52/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "category": {
                            "value": "手机"
                        }
                    }
                }
            ],
            "filter": [
                {
                    "range": {
                        "basePrice": {
                            "gte": 1000,
                            "lte": 3000
                        }
                    }
                }
            ]
        }
    },
    "from": 0,
    "size": 10,
    "sort": [
        {
            "basePrice": {
                "order": "desc"
            }
        }
    ]
}

你可能感兴趣的:(elasticsearch)