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"
            }
        }
    ]
}
上一篇:分词器的安装与使用


下一篇:Ik_fast