zoukankan      html  css  js  c++  java
  • 【ElasticSearch】添加、更新、删除索引和文档

    【ElasticSearch】添加、更新、删除索引和文档

    ======================================================================

    索引

    1、添加

    2、更新

    3、删除

    4、关闭打开

    文档

    1、添加

    2、更新

    3、删除

    ======================================================================

    索引

    1、添加

    PUT get-together
    {
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 1
      },
      "mappings": {
        "properties": {
          "name": {
            "type": "text",
            "index": true
          }
        }
      }
    }

    2、更新

    PUT get-together/_mapping
    {
      "properties": {
        "age": {
          "type": "integer"
        }
      }
    }

    3、删除

    DELETE get-together

    4、关闭打开

    POST get-together/_close
    POST get-together/_open

    文档

    1、添加

    PUT get-together/_doc/1
    {
      "name": "Jim Green",
      "age": 28
    }

    2、更新

    更新部分文档(必须存在)

    POST get-together/_update/1
    {
      "doc": {
        "name": "Alice Smith"
      }
    }

    upsert更新或添加文档

    POST get-together/_update/2
    {
      "doc": {
        "name": "Alice Smith"
      },
      "upsert": {
        "name": "Alice Smith",
        "age": 0
      }
    }

    通过脚本更新文档

    lang painless(默认),expression

    POST get-together/_update/1
    {
      "script": {
    "lang": "painless",
    "source": "ctx._source.age = params.incnum", "params": { "incnum": 13 } } }

    条件更新文档

    POST get-together/_update_by_query
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "age": {
                  "value": "28"
                }
              }
            }
          ]
        }
      }, 
      "script": {
        "lang": "painless", 
        "source": "ctx._source.name = params.newname",
        "params": {
          "newname": "this is new name"
        }
      }
    }

    3、删除

    删除单个文档

    DELETE get-together/_doc/1

    条件删除文档

    POST get-together/_delete_by_query
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "age": {
                  "value": 28
                }
              }
            }
          ]
        }
      }
    }
  • 相关阅读:
    VMware Workstation 14 Pro永久激活密钥
    maven属性、profile、资源过滤、不同环境构建项目
    控制返回前台字段
    jsonp 返回以前必须要再转一次json
    doPost方法不支持 a 标签和地址栏直接输入地址访问
    设置响应头控制浏览器的缓存
    获取请求头、设置响应头、设置缓冲区
    重定向与错误发送
    文件下载
    web 应用响应乱码问题
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/14425834.html
Copyright © 2011-2022 走看看