美文网首页
kibana 使用

kibana 使用

作者: H丶ym | 来源:发表于2021-01-28 14:38 被阅读0次

    Discover

    在查询框里,KQL您可以输入 Elasticsearch 查询语句 来搜索您的数据

    搜索关键字key
    key:*
    搜索关键字key,值value
    key:value
    搜索关键字key,值value1 或 value2
    key:(value1 OR value2)

    如果value中是一个很长的字符串,并且中间有短语 类似"my name is xxxx"
    可以使用key:"my name"

    对于数字字段您可以使用比较运算符,例如大于(>)、小于(<)或等于(=)
    status>200
    status>200 AND url_parameter_count>2
    NOT status:200

    Visualize 可视化视图

    buckets:把符合您搜索条件的文档分成不同类别
    Aggregation:聚合类型
    Field:字段
    Metrics:度量(常用count、Unique Count(选择设备唯一标识))

    饼图Pie

    画一个版本分布的饼图

    1. 点击 Split Slices 桶类别
    2. 从 Aggregation 列表中选择 Terms 。
    3. 从 Field 列表中选择 version 字段。
      得到


    我们在此饼图内,再加一个捅,比如查询每个版本年龄段的分布

    1. 点击 Split Slices 桶类别。
    2. 从 Aggregation 列表中选择 Range 。
    3. 从 Field 列表中选择 age 字段。
    4. 点击 Add Range 增加区间总数
    5. 定义以下区间:
      0 18
      18 30
      30 50
    折线图 Line
    1. 选择Y轴的Aggregation
    2. 给Y轴起个名字Custom label
      3.创建一个bucket,指定Aggregation
      4.创建x轴

    Dev Tools (ES语法)

    常用关键字
    _search:按条件搜索
    _count:查询符合条件的数量
    query:搜索参数
    match:模糊搜索,分词
    term:精准搜索,erm结合bool使用,不进行分词
    should是或,must是与,must_not是

    1. match_all: 匹配所有
    GET /索引/_search
    {
      "query":{
        "match_all": {}
      }
    }
    
    1. match:name中包含“nfc”
    GET /索引/_search
    {
      "query": {
        "match": {
          "name": "nfc"
        }
      }
    }
    

    3、 sort:按照价格倒序排序

    GET /索引/_search
    {
      "query": {
        "multi_match": {
          "query": "nfc",
          "fields": ["name","desc"]
        }
      },
      "sort": [
        {
          "price": "desc"
        }
      ]
    }
    

    4、 multi_match:根据多个字段查询一个关键词,name和desc中包含“nfc”的doc

    GET /索引/_search
    {
      "query": {
        "multi_match": {
          "query": "nfc",
          "fields": ["name","desc"]
        }
      },
      "sort": [
        {
          "price": "desc"
        }
      ]
    }
    

    5、_source 元数据:想要查询多个字段,例子中为只查询“name”和“price”字段。

    GET /索引/_search
    {
      "query":{
        "match": {
          "name": "nfc"
        }
      },
      "_source": ["name","price"]
    }
    

    6、分页(deep-paging):查询第一页(每页两条数据)

    GET /product/_search
    {
      "query":{
        "match_all": {}
      },
      "sort": [
        {
          "price": "asc"
        }
      ],
      "from": 0,
      "size": 2
    }
    

    1、bool

    可以组合多个查询条件,bool查询也是采用more_matches_is_better的机制,因此满足must和should子句的文档将会合并起来计算分值。

    ①must:必须满足

    子句(查询)必须出现在匹配的文档中,并将有助于得分。

    ②filter:过滤器,不计算相关度分数

    子句(查询)必须出现在匹配的文档中。但是不像 must查询的分数将被忽略。

    Filter子句在filter上下文中执行,这意味着计分被忽略,并且子句被考虑用于缓存。

    ③should:可能满足 or

    子句(查询)应出现在匹配的文档中。

    ④must_not:必须不满足 不计算相关度分数

    子句(查询)不得出现在匹配的文档中。子句在过滤器上下文中执行,这意味着计分被忽略

    并且子句被视为用于缓存。由于忽略计分,0因此将返回所有文档的分数。

    ⑤minimum_should_match:should配合使用,满足几个should条件

    ⑥range:lt大于,gt小于

    bool多条件 name包含xiaomi 不包含erji 描述里包不包含nfc都可以,价钱要大于等于4999

    GET /product/_search
    {
      "query": {
      "bool":{
        #name中必须不能包含“erji”
          "must": [
            {"match": { "name": "xiaomi"}}
          ],
        #name中必须包含“xiaomi”
          "must_not": [
            {"match": { "name": "erji"}}
          ],
        #should中至少满足0个条件,参见下面的minimum_should_match的解释
          "should": [
            {"match": {
              "desc": "nfc"
            }}
          ], 
        #筛选价格大于4999的doc
          "filter": [        
            {"range": {
              "price": {
                "gt": 4999   
              }
            }}
          ]
        }
      }
    }
    

    组合查询
    搜索一台xiaomi nfc phone或者一台满足 是一台手机 并且 价格小于等于2999

    GET /product/_search
    {
      "query": {
        "constant_score": {
          "filter": { 
            "bool":{
              "should":[
                {"match_phrase":{"name":"xiaomi nfc phone"}},
                {
                  "bool":{
                    "must":[
                      {"term":{"name":"phone"}},
                      {"range":{"price":{"lte":"2999"}}}
                      ]
                  }
                }
              ]
            }
          }
        }
      }
    }
    

    高亮

    GET /product/_search
    {
        "query" : {
            "match_phrase" : {
                "name" : "nfc phone"
            }
        },
        "highlight":{
          "fields":{
             "name":{}
          }
        }
    }
    

    相关文章

      网友评论

          本文标题:kibana 使用

          本文链接:https://www.haomeiwen.com/subject/nbcttltx.html