Elasticsearch学习笔记之—index管理

GET /_cat/nodes?v
GET /_cat/health?v

 

1、索引建立

PUT /location?pretty

2、查看索引

GET /_cat/indices?v

3、删除索引命令

DELETE /location?pretty

4、部分字段索引更新

POST /ecommerce/product/1/_update
{
  "doc": {
    "name": "新值"
  }
} 

5、索引信息全部更新

PUT /ecommerce/product/1
{
  "id":2, 
  "name": "test yagao2444", 
  "desc": "youxiao fangzhu2555"
}

6、删除单条索引

DELETE /music/children/1

 

批量处理

1、根据文档id批量获得文档内容

第一种:

复制代码
GET /_mget
{
 "docs":[
   {
     "_index":"music",
     "_type":"children",
     "_id":"1"
   },
   {
     "_index":"music",
     "_type":"children",
     "_id":"2"
   }
 ]
}
复制代码

 第二种:

GET /music/children/_mget
{
    "ids": [1, 2]
}

第三种:

复制代码
GET /music/children/_mget
{
   "docs" : [
      {
         "_id":1
      },
      {
         "_id":2
      }
   ]
}
复制代码

2、批量新增

POST /_bulk
{ "index": { "_index": "ecommerce", "_type":"product"}}
{ "name": "test yagao", "desc": "youxiao fangzhu"}
{ "index": { "_index": "ecommerce", "_type":"product"}}
{ "name": "test yagao2", "desc": "youxiao fangzhu2"}
POST /_bulk
{"index": { "_index": "ecommerce", "_type":"product","_id":1}}
{"id":1, "name": "test yagao", "desc": "youxiao fangzhu"}
{"index": { "_index": "ecommerce", "_type":"product","_id":2}}
{"id":2, "name": "test yagao2", "desc": "youxiao fangzhu2"}

3、批量删除

POST /_bulk
{ "delete": { "_index": "ecommerce", "_type": "product", "_id": "1"}}
{ "delete": { "_index": "ecommerce", "_type": "product", "_id": "2"}}

4、批量更新

POST /_bulk
{ "update": { "_index": "ecommerce", "_type": "product", "_id": "1","retry_on_conflict" : 3 }}
{ "doc" : {"name" : "new_name1"} }
{ "update": { "_index": "ecommerce", "_type": "product", "_id": "2","retry_on_conflict" : 3 }}
{ "doc" : {"name" : "new_name2"} }

  每次update都会调用 InternalEngine 中的get方法,来获取整个文档信息,从而实现针对特定字段进行修改,这也就导致了每次更新要获取一遍原始文档,性能上会有很大影响。所以根据使用场景,有时候使用index会比update好很多。

5、index和create区别

  index不管存在不存在,都会执行成功,如果没有指定version,version会自增。

  create如果存在,就不创建了,如果不存在就创建。

posted @   星星c#  阅读(584)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示