ES Common Operational Records

Article directory

1. Create an index

[PUT]-> ip: 9200/index_name, requester:

{
	"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. Delete all data in an index

[POST]-> http://ip:9200/index_name/type_name/_delete_by_query, requester:

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

3. View document mapping

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

4. Adding fields to existing mapping s

[PUT]-> http://ip:9200/index_name/_mapping/type_name, requester:

{
  "properties": {
        // Fields to be added
       "shopId": {
       "type": "long"
       }
   }
}

5. Delete Index

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

6. Create/delete/switch aliases

[POST]-> http://ip:9200/_aliases, requester body (the following request is atomic, or you can create or delete only one behavior):

{
    "actions": [
        {
            "remove": {
                "index": "index_a",
                "alias": "test_alias"
            }
        },
        {
            "add": {
                "index": "index_b",
                "alias": "test_alias"
            }
        }
    ]
}

Posted by mojodojo on Sat, 05 Oct 2019 13:34:26 -0700