Kibana语句

本文详细介绍了如何使用Kibana进行数据查询和分析,包括构建复杂的搜索语句、可视化数据以及通过Elasticsearch进行数据检索。适合对日志分析和监控感兴趣的Java开发者阅读。
摘要由CSDN通过智能技术生成

1. 1建立一个映射索引

在这里插入图片描述
在这里插入图片描述

PUT product
{
   
  "mappings": {
   
    "properties": {
   
      "skuId": {
   
        "type": "long"
      },
      "spuId": {
   
        "type": "keyword"
      },
      "skuTitle": {
   
        "type": "text",
        "analyzer": "ik_smart"  //ik 分词器
      },
      "skuPrice": {
   
        "type": "keyword"
      },
      "skuImg": {
   
        "type": "keyword",
        "index": false,   //字段不会被索引,不能用来搜索
        "doc_values": false  //不排序
      },
      "saleCount": {
   
        "type": "long"
      },
      "hasStock": {
   
        "type": "boolean"
      },
      "hotScore": {
   
        "type": "long"
      },
      "brandId": {
   
        "type": "long"
      },
      "catelogId": {
   
        "type": "long"
      },
      "brandName": {
   
        "type": "keyword",
        "index": false,
        "doc_values": false
      },
      "brandImg": {
   
        "type": "keyword",
        "index": false,
        "doc_values": false
      },
      "catalogName": {
   
        "type": "keyword",
        "index": false,
        "doc_values": false
      },
      "attrs": {
   
        "type": "nested",  //属性为一个List<对象>,声明为 嵌套式
        "properties": {
   
          "attrId": {
   
            "type": "long"
          },
          "attrName": {
   
            "type": "keyword",
            "index": false,
            "doc_values": false
          },
          "attrValue": {
   
            "type": "keyword"
          }
        }
      }
    }
  }
}

1.2 商品的全局查询和聚合分析功能

在这里插入图片描述

GET product/_search
{
   
  "query": {
   
    "bool": {
       //复合查询
      "must": [
        {
   
          "match": {
      //模糊查询,keyword=华为
            "skuTitle": "华为"   
          }
        }
      ],
      "filter": [//过滤,不产生分数优化查询速度(按照属性,分类,品牌,价格区间,库存
        {
              //模糊检索推荐使用match -> 文本字段使用
          "term": {
       //精确检索推荐使用term -> 非文本字段使用
            "catelogId": "225"
          }
        },
        {
   
          "terms": {
      
            "brandId": [
              "1",
              "2",
              "9"
            ]
          }
        },
        {
   
          "nested": {
     //嵌套查询
            "path": "attrs",
            "query": {
   
              "bool": {
   
                "must": [
                  {
   
                    "term": {
   
                      "attrs.attrId": {
   
                        "value": "15"
                      }
                    }
                  },
                  {
   
                    "terms": {
   
                      "attrs.attrValue": [
                        "海思(Hisilicon)",
                        "以官网信息为准"
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        {
   
          "term": {
   
            "hasStock": "true"
          }
        },
        {
   
          "range": {
   
            "skuPrice": {
      //价格区间
              "gte": 0,
              "lte": 6000
            }
          }
        }
      ]
    }
  },
  "sort": [   //排序 降序
    {
   
      
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值