9.elasticsearch索引管理(2019-05-18)

注:Elasticsearch 6.0 之后建立索引时弃用type,即尽量不要在同一索引中建立多个类型,type全部使用_doc。以下命令全部在Kibana工具上操作:
一、索引操作:
1.创建索引:
PUT  /twitter?pretty

2.获取索引:
GET /twitter

3.检查索引是否存在:
HEAD /twitter

4.删除索引:
DELETE /twitter


二、settings操作:
1.新建索引并且设置settings和mappings:
PUT /twitter
{
    "settings" : {
        "number_of_shards" : 5,
        "number_of_replicas" : 1
    },
    "mappings" : {
        "properties" : {
            "field1" : { "type" : "text" }
        }
    }
}

2.获取setting:
GET /twitter/_settings


三、mappings(映射)操作:
映射是定义文档及其包含字段的存储和索引方式的过程。
1.单独设置mapping:
PUT /twitter/_mapping 
{
  "properties": {
    "email": {
      "type": "keyword"
    }
  }
}

2.获取mapping:
GET /twitter/_mapping

3.设置索引时设置mapping:
PUT /twitter
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "user_name": {
        "type": "keyword"
      },
      "email": {
        "type": "keyword"
      },
      "content": {
        "type": "text"
      },
      "tweeted_at": {
        "type": "date"
      }
    }
  }
}


四、索引别名操作:
1.给索引增加别名:
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "twitter",
        "alias": "alias1"
      }
    }
  ]
}

2.删除索引别名:
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "twitter",
        "alias": "alias1"
      }
    }
  ]
}

五、分析器:
1.标准分析器:
GET _analyze
{
  "analyzer" : "standard",
  "text" : "this is a test"
}

2.过滤器:
GET _analyze
{
  "tokenizer" : "keyword",
  "filter" : ["lowercase"],
  "text" : "This Is A Test"
}


六、刷新:
1.刷新数据,让刚插入的数据可以被搜索到:
POST /twitter/_refresh


七、显示错误:
所有请求的URI后面带上(?error_trace=true)参数,可以显示错误的堆栈信息。例如:
GET /test_index/test_type/_search?error_trace=true
 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值