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"
            }
        }
    ]
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Elasticsearch是一个分布式的开源搜索和分析引擎,它可以快速地存储、搜索和分析大量的数据。它支持实时搜索和分析,并可以扩展到数百台服务器上处理PB级别的数据。Elasticsearch最初是作为Lucene搜索引擎的扩展而创建的,它提供了更好的性能、可扩展性和易用性。 Elasticsearch中的数据被存储在一个或多个索引中,每个索引包含一些文档。文档是以JSON格式表示的,可以包含各种类型的数据。例如,一个文档可以代表一个产品、一篇文章或一条日志记录。 以下是一些常用的Elasticsearch文档操作: 1. 创建索引 要创建一个索引,需要定义一个映射,这个映射描述了索引中文档的结构。映射是一个包含字段及其类型、分析器和其他属性的JSON对象。例如,下面是一个创建名为“my_index”的索引的映射的示例: ``` PUT /my_index { "mappings": { "properties": { "title": { "type": "text" }, "description": { "type": "text" }, "price": { "type": "float" } } } } ``` 2. 添加文档 要添加一个文档,需要指定文档所属的索引、文档ID和文档内容。例如,下面是一个添加具有ID“1”的文档的示例: ``` PUT /my_index/_doc/1 { "title": "Product 1", "description": "This is the first product", "price": 19.99 } ``` 3. 获取文档 要获取一个文档,需要指定文档所属的索引和文档ID。例如,下面是一个获取具有ID“1”的文档的示例: ``` GET /my_index/_doc/1 ``` 4. 更新文档 要更新一个文档,需要指定文档所属的索引、文档ID和需要更新的字段及其新值。例如,下面是一个将文档的价格更新为29.99的示例: ``` POST /my_index/_update/1 { "doc": { "price": 29.99 } } ``` 5. 删除文档 要删除一个文档,需要指定文档所属的索引和文档ID。例如,下面是一个删除具有ID“1”的文档的示例: ``` DELETE /my_index/_doc/1 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值