elasticsearch常用命令

最近接触到elasticsearch,需要使用命令进行多种操作,由于对es不是很熟悉,记录一下常用的curl和kinaba命令。

1.查询es信息

curl

curl -XGET "http://192.168.10.101:9200/" -H "kbn-xsrf: reporting"

kibana

GET /

2.查询所有索引信息

curl

curl -XGET "http://192.168.10.101:9200/_cat/indices?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/indices?v

3.查询节点状态

curl

curl -XGET "http://192.168.10.101:9200/_cat/nodes?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/nodes?v

4.查询索引结构信息

curl

curl -XGET "http://192.168.10.101:9200/proof_data?pretty=true" -H "kbn-xsrf: reporting"

kibana

GET /proof_data?pretty=true

5.创建索引

curl

curl -XPUT "http://192.168.10.101:9200/new_index_data/" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "BIZ_ID" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "BIZ_TYPE_ID" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "CHANNEL" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "CREATE_TIME" : {
          "type" : "date"
        },
        "ORGANIZE_CODE" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "TRANSACTION_ID" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "USER_ID" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "USE_ENCRYPT" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "id" : {
          "type" : "long"
        },
        "virtual_channel_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
}'

kibana

PUT /new_index_data/
{

    "aliases" : { },

    "mappings" : {

      "properties" : {

        "BIZ_ID" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "BIZ_TYPE_ID" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "CHANNEL" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "CREATE_TIME" : {

          "type" : "date"

        },

        "ORGANIZE_CODE" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "TRANSACTION_ID" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "USER_ID" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "USE_ENCRYPT" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        },

        "id" : {

          "type" : "long"

        },

        "virtual_channel_id" : {

          "type" : "text",

          "fields" : {

            "keyword" : {

              "type" : "keyword",

              "ignore_above" : 256

            }

          }

        }

      }

    }

}

6.查询索引的Settings配置

curl

curl -XGET "http://192.168.10.101:9200/new_index_data/_settings" -H "kbn-xsrf: reporting"

kibana

GET /new_index_data/_settings

7.查询索引下所有数据

curl

在search后面加上?pretty,能让返回的json格式化。

# 带条件查询
curl -XGET "http://192.168.10.101:9200/proof_data/_search" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{
  "query": {
    "match_all": {}
  }
}'

# 不带条件查询
curl -XGET "http://192.168.10.101:9200/proof_data/_search" -H "kbn-xsrf: reporting"

kibana

GET /proof_data/_search
{

  "query": {

    "match_all": {}

  }

}

8.查询索引下数据总量

curl

curl -XGET "http://192.168.10.101:9200/proof_data/_count" -H "kbn-xsrf: reporting"

kibana

GET /proof_data/_count

9.删除索引

curl

curl -XDELETE "http://192.168.10.101:9200/new_index_data/" -H "kbn-xsrf: reporting"

kibana

DELETE /new_index_data/

10.删除索引下的数据

curl

curl -XPOST "http://192.168.10.101:9200/index_name/_delete_by_query" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{
  "query":{
    "match_all":{}
  }
}'

此语句可以根据query条件,进行选择性删除数据。

kibana

POST /index_name/_delete_by_query
{
  "query":{
    "match_all":{}
  }
}

11.查询es健康状况

curl

curl -XGET "http://192.168.10.101:9200/_cat/health?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/health?v

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Winter Liu

别说话,打赏就行了!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值