zoukankan      html  css  js  c++  java
  • elasticsearch权威指南(v7.9.3)

    一、参考

    Elasticsearch: 权威指南

    二、名词解释

    (1) DSLdomain-specific language,领域特定语言

    三、基础入门

    3.1 索引员工文档

    变更:

    一个索引下没有多个type, 只有一个_doc的类型

    # 索引一个文档
    PUT /megacorp/_doc/1
    {
        "first_name" : "John",
        "last_name" :  "Smith",
        "age" :        25,
        "about" :      "I love to go rock climbing",
        "interests": [ "sports", "music" ]
    }
    
    # 返回值
    
    {
      "_index" : "megacorp",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 1,
      "result" : "created",
      "_shards" : {
        "total" : 2,
        "successful" : 2,
        "failed" : 0
      },
      "_seq_no" : 0,
      "_primary_term" : 1
    }
    
    
    

    3.2 检索文档

    # 检索文档
    GET megacorp/_doc/1
    
    # 返回值
    {
      "_index" : "megacorp",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 1,
      "_seq_no" : 0,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "first_name" : "John",
        "last_name" : "Smith",
        "age" : 25,
        "about" : "I love to go rock climbing",
        "interests" : [
          "sports",
          "music"
        ]
      }
    }
    
    
    

    3.3 短语查询

    # 查询语句
    GET /megacorp/_search
    {
      "query": {
        "match_phrase": {
          "about": "rock climbing"
        }
      }
    }
    
    # 返回值
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.4167401,
        "hits" : [
          {
            "_index" : "megacorp",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.4167401,
            "_source" : {
              "first_name" : "John",
              "last_name" : "Smith",
              "age" : 25,
              "about" : "I love to go rock climbing",
              "interests" : [
                "sports",
                "music"
              ]
            }
          }
        ]
      }
    }
    
    

    3.4 高亮查询

    # 高亮查询
    GET /megacorp/_search
    {
      "query": {
        "match_phrase": {
          "about": "rock climbing"
        }
      },
      "highlight": {
        "fields": {
          "about": {}
        }
      }
    }
    
    # 返回值
    {
      "took" : 79,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.4167401,
        "hits" : [
          {
            "_index" : "megacorp",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.4167401,
            "_source" : {
              "first_name" : "John",
              "last_name" : "Smith",
              "age" : 25,
              "about" : "I love to go rock climbing",
              "interests" : [
                "sports",
                "music"
              ]
            },
            "highlight" : {
              "about" : [
                "I love to go <em>rock</em> <em>climbing</em>"
              ]
            }
          }
        ]
      }
    }
    
    

    3.5 分析

    # 聚合查询
    GET /megacorp/_search
    {
      "size": 0, 
      "query": {
        "match": {
          "last_name": "smith"
        }
      },
      "aggs": {
        "all_interests": {
          "terms": {
            "field": "interests.keyword"
          },
          "aggs": {
            "avg_age": {
              "avg": {
                "field": "age"
              }
            }
          }
        }
      }
    }
    
    # 返回值
    {
      "took" : 3,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : null,
        "hits" : [ ]
      },
      "aggregations" : {
        "all_interests" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : "music",
              "doc_count" : 2,
              "avg_age" : {
                "value" : 28.5
              }
            },
            {
              "key" : "sports",
              "doc_count" : 1,
              "avg_age" : {
                "value" : 25.0
              }
            }
          ]
        }
      }
    }
    

    四、集群内的原理

  • 相关阅读:
    微信小程序:动画(Animation)
    小程序滚动事件之头部渐隐渐现demo
    小程序tab栏可滑动,可点击居中demo
    ES7中前端异步特性:async、await。
    vue中生成二维码
    vue之vue-cookies
    echarts中boundaryGap属性
    ES6数组方法总结
    手写自己的ORM框架For SQlServer(简单的CURD)
    Sqlsever新增作业执行计划傻瓜式操作
  • 原文地址:https://www.cnblogs.com/thewindyz/p/13932048.html
Copyright © 2011-2022 走看看