Elasticsearch 基本操作

Elasticsearch 基本操作

集群

查看集群健康度
GET /_cat/health?v

curl -XGET "http://localhost:9200/_cat/health?v"

响应:

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1475247709 17:01:49  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%
查看集群健康度会获取三种状态
  • 绿色——一切都好(群集完全正常工作)
  • 黄色——所有数据都可用,但一些副本尚未分配(群集完全正常工作)
  • 红色——有些数据不管出于什么原因都不可用(集群部分功能正常)
列出集群所有节点
GET /_cat/health?v

curl -X GET "localhost:9200/_cat/health?v"
列出所有的索引
GET /_cat/indices?v

curl -X GET "localhost:9200/_cat/indices?v"

索引的使用

创建索引
  • 创建默认配置的索引 customer,5 个基础分片,1 个复制集(必须需要 2 个节点才可用)。
PUT /customer?pretty

curl -X PUT "localhost:9200/customer?pretty"
  • 指定设置和映射
curl -X PUT "localhost:9200/test" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 1,
        "number_of_replicas" : 2,
        "refresh_interval": "1s" //默认值
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "field1" : { "type" : "text" }
            }
        }
    }
}
'
删除
  • 删除索引可以使用模糊匹配等多种选择
DELETE /my_index?pretty
DELETE /index_one,index_two
DELETE /index_*
DELETE /_all
DELETE /*

curl -X DELETE "localhost:9200/customer?pretty"
# 结果
{
   
  "acknowledged" : true
}

映射

单索引映射
  1. 创建索引时创建映射
curl -X PUT "localhost:9200/test" -H 'Content-Type: application/json' -d'
{
    "mappings" : {
        "_doc" : {
            "properties" : {
                "field1" : { "type" : "text" }
            }
        }
    }
}
'
  1. 在存在的索引中添加映射
curl -X PUT "localhost:9200/twitter" -H 'Content-Type: application/json' -d'
{}
'
curl -X PUT 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值