手动分配索引

通过“GET _cat/shards/indexname”错误信息如下,从shard无法分配,主shard正常,正常的shard未展示出来:

indexname                3     r      UNASSIGNED                                 
indexname                4     r      UNASSIGNED                                 
indexname                1     r      UNASSIGNED  

手动分片之前需要禁止自动分片,cluster.routing.allocation.disable_allocation参数设置为true
尝试手动分片:

#动态设置es索引副本数量
curl -XPUT 'http://168.7.1.67:9200/log4j-emobilelog/_settings' -d '{
   "number_of_replicas" : 2
}'

#设置es不自动分配分片
curl -XPUT 'http://168.7.1.67:9200/log4j-emobilelog/_settings' -d '{
   "cluster.routing.allocation.disable_allocation" : true
}'

# 手动移动分片
curl -XPOST "http://168.7.1.67:9200/_cluster/reroute' -d  '{
   "commands" : [{
		"move" : {
			"index" : "log4j-emobilelog",
			"shard" : 0,
			"from_node" : "es-0",
			"to_node" : "es-3"
		}
	}]
}'

# 手动分配分片
curl -XPOST "http://168.7.1.67:9200/_cluster/reroute' -d  '{
   "commands" : [{
		"allocate" : {
			"index" : ".kibana",
			"shard" : 0,
			"node" : "es-2",
		}
	}]
}'

ES的license由trial更改为为basic
## 查看
curl -u elastic:zhxx -X DELETE http://127.0.0.1:9200/_license?pretty

### 修改成basic认证
curl -H "Content-type:application/json" -X POST http://localhost:9200/_xpack/license/start_basic?acknowledge=true -u elastic:xxx
Fielddata 状态查询

业务的java的报错:Fielddata is disabled on text fields by default. Set fielddata=true on [meetingId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.

# 先查看索引的mapping 的字段
curl http://10.189.128.16:9200/index_name/_mapping/_search
## 查看mapping 中 字段信息
curl http://10.189.128.16:9200/index_name/_mapping/docs

写入es数据

POST knight/_doc
{
  "name":"tom",
  "city":"cs"
}  
查询最新的es数据
GET ccms_callout_detail_xx/_search
{
  "size": 20,
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "callTime": {
        "order": "desc"
      }
    }
  ]
  
}

集群监控状态检查

背景: 服务器安全部门限制得死,很多装不了,本地办公网也无法访问。所以总结一些通过curl查看的一些命令

## 
curl -s http://10.124.20.76:9200/_cat/health
##
curl http://10.124.20.76:9200/_cat/indices
查询带指定Mapping的索引
​
PUT xxoo
{
  "mappings":{
      "properties":{
        "@timestamp":{
          "type":"date",
          "format":"yyyy-MM-dd HH:mm:ssSSSS"
        }
      }
    }
}
索引重命名

背景: 比如开发要求删除某一个索引,但是运维需要备份索引,然后再删除。

备注: 如果原来的索引有自建的mapping,需要先建好索引对应的mapping,然后再通过reindex做数据迁移。

​
# dev tools 操作,先复制索引的数据到新索引(新索引会自动创建)
POST _reindex
{
  "source": {
    "index": "test-knight-01-daemon-2021.08.30"
  }
  , "dest": {
    "index":"test-knight-01-daemon-backup-01"
  }
}
# 然后直接删除旧索引
delete test-knight-01-daemon-2021.08.30
Mapping操作
## mapping 相当于es的字段
###  查询
GET /test_2020-10-21/_mapping?pretty
{
  "test_2020-10-21" : {
    "mappings" : { }
  }
}

##  添加mapping操作
PUT xx/_mapping/xx_oiltrip_search
{
    "properties": {
        "rebateReportAmount": {
            "null_value": 0,
	        "type": "double"
        },
        "rebateReportBalance": {
            "null_value": 0,
	        "type": "double"
        },
        "rebateReportStatus":{
            "null_value":"",
            "type":"keyword"
        },
        "rebateSource":{
            "null_value":"",
            "type":"keyword"
        }
    }
}

为索引起别名
## eg: knight: 为原索引名
## 删除索引
curl -X DELETE 127.0.0.1:9200/articles

## 设置别名
curl -X PUT 127.0.0.1:9200/knight/_alias/knight_bieming

# 查看索引有哪些别名
curl 127.0.0.1:9200/knight/_alias/*

# 查看别名对应的索引
curl 127.0.0.1:9200/_alias/knight_bieming
Logo

一站式 AI 云服务平台

更多推荐