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
                }
              }
            }
          ]
        }
      }
    }
  • 相关阅读:
    js 实现自增长
    常用的js脚本验证
    Jquery 收集
    Jquery 常用操作搜集
    Jquery 点击绑定行 弹出详细页面
    Jquery 了解
    Html 标尺
    Editor Guidelines
    程序员需要做到
    jS 回车事件
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/14425834.html
Copyright © 2011-2022 走看看