索引创建
PUT /index_name
{
"settings": {
"index": {
"refresh_interval": "30s",
"number_of_shards": "3",
"max_result_window": "100000000",
"analysis": {
"filter": {
"escapeLen": {
"type": "length",
"max": "30",
"min": "2"
}
},
"analyzer": {
"escapeHtml": {
"filter": [
"escapeLen"
],
"char_filter": [
"html_strip"
],
"tokenizer": "ik_smart"
}
}
},
"number_of_replicas": "2"
}
}
}
POST /index_name/_mapping
{
"properties": {
"content": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "escapeHtml",
"search_analyzer": "ik_smart"
},
"title": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "escapeHtml",
"search_analyzer": "ik_smart",
"fielddata": true
}
}
}
索引删除
DELETE /my_index_name
判断字段是否存在
POST myindex/_search
{
"query": {
"bool": {
"must": [
{
"exists": {"field": "match_title"}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"track_total_hits": 2147483647
}
增加数据
PUT myindex/_doc/{id}
{
"title":"1111",
"content":"22222"
}
yellow 排查解决 常见请求
GET /_cat/shards?h=index,shard,prirep,state,unassigned.reason 查询原因
GET /_cluster/health 查询健康
GET /_cluster/allocation/explain?pretty
GET /index_name/_settings 查看设置
PUT /index_name/_settings 重置分片
{"number_of_replicas": 0}
PUT /index_name/_settings 重新分配
{"number_of_replicas": 2}
reached the limit of incoming shard recoveries [2], cluster setting [cluster.routing.allocation.node_concurrent_incoming_recoveries=2] (can also be set via [cluster.routing.allocation.node_concurrent_recoveries])
这种情况通常出现在集群重启,或者某一个节点重启后。且由于设置的分片并发恢复的值较低导致。为了尽快恢复集群健康状态。
解决方法:可以通过调用下面的API来提升分片恢复的速度和并发度:
PUT /_cluster/settings
{
"transient" : {
"cluster.routing.allocation.node_concurrent_recoveries": "20",
"indices.recovery.max_bytes_per_sec": "100mb"
}
}