关于elasticsearch:ES常用命令

2次阅读

共计 2760 个字符,预计需要花费 7 分钟才能阅读完成。

ES 集体罕用的一些命令

查问相干命令

# 查看所有的 cat 操作
GET /_cat
#查看节点信息
GET /_cat/nodes?v 
#查看集群以后状态:红、黄、绿
GET /_cluster/health
#查看集群详情
GET /_cluster/stats
#查看集群期待工作
GET /_cluster/pending_tasks


#查看指定索引的全副信息
GET /indextest001
#查看指定索引的配置信息
GET /indextest001/_settings?
#查看指定索引的属性信息
GET /indextest001/_mapping?
#查看索引全副文档
GET rollover_test-000001/_search
{
  "query": {"match_all": {}
  }
}
#查看索引生命周期
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
#查看 master 节点信息
GET /_cat/master?v
#查看索引的文档数量
GET /_cat/count/career_plan_sku_index_52?v
#查看所有 index 的段信息
GET /_cat/segments?v
#查看所有 index 的别名信息
GET /_cat/aliases?v
#查看索引别名有哪些索引援用
GET /_cat/aliases/rollover_test_alias

一些批改相干实例操作

# 批改索引分片数量
PUT /indextest001/_settings
{
    "settings": {"number_of_replicas": 0}
}

#创立索引
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"}
    }
}

#查看索引对应了哪些别名
GET indextest001/_alias

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

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

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

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

#查看集群配置
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
  }
}
#应用模板创立索引
PUT rollover_test-000001 
{
  "aliases": {
    "rollover_test_alias":{"is_write_index": true}
  }
}
#查看索引生命周期
GET rollover_test-000001/_ilm/explain
#查看索引全副文档
GET rollover_test-000001/_search
{
  "query": {"match_all": {}
  }
}
#查看索引别名
GET _alias/rollover_test_alias
#索引减少文档
POST /rollover_test-000001/_doc
{"name": "caodewang"}

#应用 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"}
        }
    ]
}
正文完
 0