zoukankan      html  css  js  c++  java
  • es操作

    基本操作

    新增数据

    {
      "name" : "yhq",
      "age" : 26,
      "sex" : "男"
    }
    

    结果

    {
      "_index": "yhq",
      "_type": "user",
      "_id": "1",
      "_version": 1,
      "result": "created",
      "_shards": { "total": 2, "successful": 1, "failed": 0 },
      "_seq_no": 0,
      "_primary_term": 1,
    }
    

    查询数据

    GET yhq/user/1
    

    结果

    {
      "_index": "yhq",
      "_type": "user",
      "_id": "1",
      "_version": 1,
      "_seq_no": 0,
      "_primary_term": 1,
      "found": true,
      "_source": { "name": "yhq", "age": 26, "sex": "男" },
    }
    
    GET /yhq/user/_search?q=name:yhq
    

    结果

    {
      "took": 46,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 1, "relation": "eq" },
          "max_score": 0.6931471,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "1",
                "_score": 0.6931471,
                "_source": { "name": "yhq-qhh", "age": 28, "sex": "男" },
              },
            ],
        },
    }
    

    更新数据

    PUT /yhq/user/1
    {
      "name" : "yhq",
      "age" : 28,
      "sex" : "男"
    }
    

    结果

    {
      "_index": "yhq",
      "_type": "user",
      "_id": "1",
      "_version": 2,
      "result": "updated",
      "_shards": { "total": 2, "successful": 1, "failed": 0 },
      "_seq_no": 2,
      "_primary_term": 1,
    }
    
    POST /yhq/user/1/_update
    {
      "doc" : {
        "name" : "yhq-qhh"
      }
    }
    

    结果

    {
      "_index": "yhq",
      "_type": "user",
      "_id": "1",
      "_version": 3,
      "result": "updated",
      "_shards": { "total": 2, "successful": 1, "failed": 0 },
      "_seq_no": 3,
      "_primary_term": 1,
    }
    

    复杂操作

    查询

    GET /yhq/user/_search
    {
      "query": {
        "match": {
          "name": "yhq"
        }
      },
      "_source": ["name","age"],
      "sort": [
        {
          "age":{
            "order": "asc"
          }
        }
      ],
      "from": 0,
      "size": 1
    }
    

    结果

    {
      "took": 5,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 2, "relation": "eq" },
          "max_score": null,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "2",
                "_score": null,
                "_source": { "name": "yhq", "age": 26 },
                "sort": [26],
              },
            ],
        },
    }
    
    GET /yhq/user/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "name": "yhq"
              }
            },
            {
              "match": {
                "age": 26
              }
            }
          ]
        }
      }
    }
    

    结果

    {
      "took": 6,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 1, "relation": "eq" },
          "max_score": 1.5619608,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "2",
                "_score": 1.5619608,
                "_source": { "name": "yhq", "age": 26, "sex": "男" },
              },
            ],
        },
    }
    
    GET /yhq/user/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "name": "yhq"
              }
            },
            {
              "match": {
                "age": 26
              }
            }
          ]
        }
      }
    }
    

    结果

    {
      "took": 4,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 2, "relation": "eq" },
          "max_score": 1.5619608,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "2",
                "_score": 1.5619608,
                "_source": { "name": "yhq", "age": 26, "sex": "男" },
              },
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "1",
                "_score": 0.43445712,
                "_source": { "name": "yhq-qhh", "age": 28, "sex": "男" },
              },
            ],
        },
    }
    
    GET /yhq/user/_search
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "match": {
                "name": "yhq"
              }
            }
          ]
        }
      }
    }
    

    结果

    {
      "took": 2,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 1, "relation": "eq" },
          "max_score": 0.0,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "12",
                "_score": 0.0,
                "_source": { "name": "张三", "age": 27, "sex": "男" },
              },
            ],
        },
    }
    

    高亮

    GET /yhq/user/_search
    {
      "query": {
        "match": {
          "name": "yhq"
        }
      },
      "highlight": {
        "fields": {
          "name" :{}
        },
        "pre_tags": "<p class='key' style='color:red'>",
        "post_tags": "</p>"
      }
    }
    

    结果

    {
      "took": 4,
      "timed_out": false,
      "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
      "hits":
        {
          "total": { "value": 2, "relation": "eq" },
          "max_score": 0.5619608,
          "hits":
            [
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "2",
                "_score": 0.5619608,
                "_source": { "name": "yhq", "age": 26, "sex": "男" },
                "highlight":
                  { "name": ["<p class='key' style='color:red'>yhq</p>"] },
              },
              {
                "_index": "yhq",
                "_type": "user",
                "_id": "1",
                "_score": 0.43445712,
                "_source": { "name": "yhq-qhh", "age": 28, "sex": "男" },
                "highlight":
                  { "name": ["<p class='key' style='color:red'>yhq</p>-qhh"] },
              },
            ],
        },
    }
    
  • 相关阅读:
    http经典解析
    js实现canvas保存图片为png格式并下载到本地
    你所不知的 CSS ::before 和 ::after 伪元素用法
    js自动下载
    CSS 实现隐藏滚动条同时又可以滚动
    checkbox与文字对齐
    利用html2canvas截图,得到base64上传ajax
    bootstrap-datepicker简单使用
    移动端禁止滚动
    h5移动网页唤起App
  • 原文地址:https://www.cnblogs.com/yhq-qhh/p/13526545.html
Copyright © 2011-2022 走看看