zoukankan      html  css  js  c++  java
  • Elasticsearch05-批量增删改查

    批量查询

    # 查询不同文档
    GET /_mget
    {
      "docs": [
        {
          "_index": "product",
          "_id":2
        },
            {
          "_index": "fields_test",
          "_id":1
        }
        ]
    }
    
    # 查询同一个文档
    GET /product/_mget
    {
      "docs": [
        {
          "_id": 2
        },
        {
          "_id": 3
        }
      ]
    }
    
    
    
    # 查询同一个文档
    GET /product/_mget
    {
      "ids":[2,3]
    }
    
    
    
    
    GET /product/_mget
    {
      "docs": [
        {
          "_id": 2,
          "_source": false #不查询字段
        },
        {
          "_id": 3,
          "_source": [   #只显示'name'、'price'字段
            "name",
            "price"
          ]
        },
        {
          "_id": 4,
          "_source": { #include包含哪些字段
            "include": [
              "name"
            ],
            "exclude":[   #exclude排除哪些字段
              "price"
              ]
          }
        }
      ]
    }

    创建

    # 手动生成id,如果存在就updated
    PUT /test_index/_doc/1/ 
    {
      "field":"test"
    }
    
    
    # 手动生成id,如果存在就报错
    PUT /test_index/_doc/3/_create
    {
      "field":"test"
    }
    
    # 手动生成id,如果存在就报错
    PUT /test_index/_create/1/
    {
      "field":"test"
    }
    
    
    #自动生产id(guid),"_id" : "YsONtnsBwRRHNrIJssjh"
    POST /test_index/_doc
    {
      "field":"test"
    }

    增、删、改

    POST /_bulk
    { "delete": { "_index": "product2",  "_id": "1" }}
    { "create": { "_index": "product2",  "_id": "2" }}
    { "name":    "_bulk create 2" }
    { "create": { "_index": "product2",  "_id": "12" }}
    { "name":    "_bulk create 12" }
    { "index":  { "_index": "product2",  "_id": "3" }}
    { "name":    "index product2 " }
    { "index":  { "_index": "product2",  "_id": "13" }}
    { "name":    "index product2" }
    { "update": { "_index": "product2",  "_id": "4","retry_on_conflict" : "3"} }
    { "doc" : {"test_field2" : "bulk test1"} }
    
    说明:
        a.retry_on_conflict 报错重试3次,针对version的乐观锁
        b.使用_bulk,body不能换行,只能一行
        c._bulk?filter_path=items.*.error  只显示失败的
        d.index存在的数据全量替换 不存在的新创建
        e.这种方式操作优点:不会占用内存

    ES并发冲突问题(悲观锁和乐观锁)

    1.悲观锁:各种情况,都加锁,读写锁、行级锁、表级锁。使用简单,但是并发能力很低
    2.乐观锁:并发能力高,操作麻烦,每次no-query操作都需要比对version
    
    # 修改的时候带上版本号
    POST /version_index/_doc/3?version=8&version_type=external
    {
      "field":"test"
    }
  • 相关阅读:
    [文摘20070723]最经典的爱情观
    [转]ASP .Net C# 下 Word开发资料
    [引]如何藉由使用 Visual C# . NET 處理 Word 中的事件
    简单的搭建Web系统常用的框架页面
    Gentle 简单配置方法之一种
    在 可编辑的 Div 的 光标位置 插入 文字 或 HTML
    [转]使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图
    VS2005 添加 Microsoft.Office.Tools.Word.dll 等引用
    要事第一 事不过三
    VC slider用法
  • 原文地址:https://www.cnblogs.com/bigdata-familyMeals/p/15231947.html
Copyright © 2011-2022 走看看