ES常用操作記錄

1. 創建索引

[PUT] -> ip:9200/index_name,請求體:

{
	"settings": {
		"analysis": {
			"filter": {
				"remote_synonym": {
					"type": "dynamic_synonym",
					"synonyms_path": "http://xxx.oss-cn-beijing.aliyuncs.com/search/synonym_dic.txt",
					"interval": "30"
				}
			},
			"analyzer": {
				"synonym_smart": {
					"filter": [
						"remote_synonym"
					],
					"tokenizer": "ik_smart"
				},
				"ik_smart": {
					"tokenizer": "ik_smart"
				},
				"ik_max_word": {
					"tokenizer": "ik_max_word"
				}
			}
		}
	},
	"mappings": {
		"doc": {
			"dynamic": false,
			"properties": {
				"id": {
					"type": "long"
				},
				"name": {
					"type": "text",
					"store": true,
					"analyzer": "ik_max_word",
					"search_analyzer": "synonym_smart"
				},
				"createTime": {
					"type": "long"
				},
				"updateTime": {
					"type": "long"
				},
				"description": {
					"type": "text",
					"store": true,
					"analyzer": "ik_max_word",
					"search_analyzer": "synonym_smart"
				},
				"subject": {
					"type": "keyword"
				},
				"status": {
					"type": "integer"
				},
			}
		}
	}
}

2. 刪除某個索引中的所有數據

[POST] -> http://ip:9200/index_name/type_name/_delete_by_query,請求體:

{
  "query": {
    "match_all": {}
  }
}

3. 查看文檔 mapping

[GET] -> http://ip:9200/index_name/_mapping/type_name

4. 向現有 mapping 中增加字段

[PUT] -> http://ip:9200/index_name/_mapping/type_name,請求體:

{
  "properties": {
        // 需要添加的字段
       "shopId": {
       "type": "long"
       }
   }
}

5. 刪除索引

[DELETE] -> http://ip:9200/index_name

6. 創建/刪除/切換別名

[POST] -> http://ip:9200/_aliases,請求體(下面的請求是原子性的,也可以只做創建或刪除一種行爲):

{
    "actions": [
        {
            "remove": {
                "index": "index_a",
                "alias": "test_alias"
            }
        },
        {
            "add": {
                "index": "index_b",
                "alias": "test_alias"
            }
        }
    ]
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章