Elasticsearch-Index索引
一.索引管理
直接put数据PUT index/_doc/1,ES会自动生成索引,并建立动态映射dynamic mapping
在生产上,需要自己手动建立索引和映射,为了更好地管理索引。就像数据库的建表语句一样
- 创建索引
PUT /index
{
"setting": {},
"mappings": {
"properties": {
"field1": {"type": "text"}, ...
}
},
"aliases": {
"default_index": {}
}
}
eg:
PUT my_index
{
"settings": { # 索引的设置
"number_of_shards": 1, # 分片数
"number_of_replicas": 1 # 副本数
},
"mappings": { # 设置映射,
"properties": {
"field1": {
"type": "text"
},
"field2": {
"type": "text"
}
}
},
"aliases": { # 别名
"default_index": {} # 可以通过my_index查询也可使用default_index查询
}
}
eg:
PUT my_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"field1": {
"type": "text"
},
"field2": {
"type": "text"
}
}
},
"aliases": {
"default_index": {}
}
}
PUT my_index/_doc/1
{
"field1": "php",
"field2": "java"
}
GET my_index/_doc/1
GET default_index/_doc/1
- 查询索引
GET my_index
GET my_index/_mapping
GET my_index/_settings
- 修改索引
修改副本数
PUT my_index/_settings
{
"index": {
"number_of_replicas" : 2
}
}
- 删除索引
DELETE /my_index
DELETE /inidex_1, index_2
DELETE /inidex_*
DELETE /_all # 删除所有索引
为了安全起见,防止恶意删除索引,删除时必须指定索引名,在elasticsearch.yml配置文件中更改
action.destructive_requires_name: true
分类:
Elasticsearch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧