zoukankan      html  css  js  c++  java
  • Elasticsearch之增删改查

    Elasticsearch的增删改查相当于CRUD,index,delete,update,get

    1.增加

    put.sh如下代码

    curl -X PUT  -uuser:password -H 'Content-Type: application/json'  'http://localhost:port/test/_doc/1' -d'
    {
            "user": "kumufengchun",
            "country":   "中国",
            "prov":   "福建",
            "city":   "unknown"
    }
    '

    返回结果

    [kumufengchun@localhost ~/es_test]$ ./put.sh
    {"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":10,"_primary_term":1}

    2.删除

    delete.sh如下代码

    curl -X POST  -uuser:password -H 'Content-Type: application/json'  'http://localhost:port/test/_delete_by_query' -d'
    {
      "query" : {
        "term" : {
          "user" : {
            "value": "kumufengchun"
          }
        }
      }
    }
    '

    返回结果

    [kumufengchun@localhost ~/es_test]$ ./delete.sh
    {"took":171,"timed_out":false,"total":1,"deleted":1,"batches":1,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[]}

    3.修改

    update.sh如下代码

    curl -X POST  -uuser:password -H 'Content-Type: application/json'  'http://localhost:port/test/_doc/1/_update' -d'
    {
      "script" : {
        "source":"ctx._source.city=params.city",
        "lang":"painless",
        "params" : {
          "city" : "厦门"
        }
      }
    }
    '

    返回结果

    [kumufengchun@localhost ~/es_test]$ ./update.sh
    {"_index":"test","_type":"_doc","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":13,"_primary_term":1}

    4.查询

    select.sh如下代码

    curl -X GET  -uuser:password -H 'Content-Type: application/json'  'http://localhost:port/test/_search' -d'
    {
      "query" : {
        "term" : {
          "prov" : {
            "value": "福建"
          }
        }
      }
    }
    '

    返回结果

    [kumufengchun@localhost ~/es_test]$ ./select.sh
    {"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"test","_type":"_doc","_id":"1","_score":1.0,"_source":
    {
            "user": "kumufengchun",
            "country":   "中国",
            "prov":   "福建",
            "city":   "unknown"
    }
    }]}}

    参考:https://www.cnblogs.com/xing901022/p/5330778.html

    https://blog.csdn.net/weixin_39471249/article/details/80358192

    https://blog.csdn.net/weixin_39471249/article/details/80427339

    https://blog.csdn.net/weixin_39471249

  • 相关阅读:
    PHP webserver 之 soap wsdl
    PHP webserver 之 soap 生成wsdl文件
    PHP webserver 之 soap non-wsdl
    CodeForces 729A Interview with Oleg (模拟)
    CodeForces 727A Transformation: from A to B (DFS)
    POJ 3111 K Best (二分)
    POJ 2456 Aggressive cows (二分)
    POJ 1064 Cable master(二分)
    POJ
    Codeforces 869B
  • 原文地址:https://www.cnblogs.com/kumufengchun/p/12857716.html
Copyright © 2011-2022 走看看