elasticsearch常用命令

Elasticsearch概念

Elasticsearch mysql
Index(索引) 数据库
Type(类型)
Documents(文档)
Fields

常用命令

索引

bash 复制代码
# 索引初始化,number_of_shards:分片数,不可修改;number_of_replicas:副本数,可修改
PUT lagou
{
  "settings": {
    "index": {
      "number_of_shards": 5,
      "number_of_replicas": 1
    }
  }
}

# 获取索引settings
GET lagou/_settings
GET _all/_settings
GET _settings

GET .kibana,lagou/_settings

# 更新索引
PUT lagou/_settings
{
"number_of_replicas":2
}


# 获取索引信息
GET _all
GET lagou

CRUD

bash 复制代码
# 新建
# 新建数据,指定id
PUT lagou/job/1
{
    "title": "python分布式爬虫",
    "salary_min":15000,
    "city":"北京",
    "company":{
        "name":"百度",
        "company_addr":"北京市软件园"
    },
    "publish_date": "2017-4-16",
    "comments":15
}

# 新建数据
POST lagou/job/
{
    "title": "python分布式爬虫",
    "salary_min":15000,
    "city":"北京",
    "company":{
        "name":"百度",
        "company_addr":"北京市软件园"
    },
    "publish_date": "2017-4-16",
    "comments":15
}


# 查询
GET lagou/job/1
# 只获取title字段
GET lagou/job/1?_source=title
# 获取title,city字段
GET lagou/job/1?_source=title,city
# 获取所有字段
GET lagou/job/1?_source


# 修改
# 覆盖更新
PUT lagou/job/1
{
    "title":"python分布式爬虫",
    "salary_min":15000,
    "company":{
        "name":"百度",
        "company_addr":"北京市软件园"
    },
    "publish_date": "2017-4-16",
    "comments":15
}

# 更新指定字段
POST lagou/job/1/_update
{
  "doc":{
    "comments":20
  }
}


# 删除
# 删除文档
DELETE lagou/job/1
# 删除索引
DELETE lagou
相关推荐
serve the people1 小时前
Elasticsearch(5) i want to monitor the es health from a http api
大数据·http·elasticsearch
Taerge01104 小时前
Doris, StarRocks, ClickHouse, Hologres, ES 对比,选型建议
大数据·clickhouse·elasticsearch
serve the people14 小时前
Elasticsearch(1) could you tell me how to use es if i am a beginner
大数据·elasticsearch·jenkins
一个儒雅随和的男子15 小时前
Elasticsearch出现深度分页问题怎么解决?
大数据·elasticsearch·搜索引擎
2601_9618454218 小时前
高考真题下载|2025高考全科真题网盘分类整理
搜索引擎·中文分词·solr·lucene·sphinx·高考
老陈头聊SEO1 天前
生成引擎优化(GEO)引领内容创作与用户体验的转型之路
其他·搜索引擎·seo优化
serve the people1 天前
Elasticsearch(3) show me some examples
大数据·elasticsearch·jenkins
是一个Bug1 天前
Elasticsearch 保姆级入门:从“找文件”到“秒级搜索”
大数据·elasticsearch·搜索引擎
serve the people1 天前
Elasticsearch(4) show me some more advanced content
大数据·elasticsearch·jenkins