Elasticsearch(二)kibana

kibana

官网下载

修改配置文件

修改vi config/kibana.yml
elasticsearch.url: “http://localhost:9200”
改成对应的地址

后台启动

nohup ./bin/kibana &

查询操作

1.索引库操作

PUT /库名
{
  "settings": {
    "number_of_shards": 1, //分片
    "number_of_replicas": 1//备份
  }
}
GET /库名
DELETE /库名

2.创建映射字段

PUT /库名/_mapping/表名
{
  "properties": {
    "字段名": {
      "type": "text",
      "index": true,
      "store": true, 
      "analyzer": "ik_max_word"
    }
  }
}
  1. type:
    string类型,分两种:
    text:可分词,不可参与聚合
    keyword:不可分词,数据会作为完整的字段进行匹配,可以参与聚合
    Numerical:数值类型
    基本数据类型:long、integer、strot、byte、double、float、half_float
    浮点数的高精度类型:scaled_float
    需要指定一个精度因子,比如10或100。elasticsearch会吧真实值乘以这个因子后存储,取出时再还原。
    Date:日期类型

  2. index:
    是否索引

  3. store:
    是否将数据额外存储
    默认为false 一般都不需要设置
    在elasticearch ,即便store为false,也可以搜索到结果。
    我们在显示的时候可以使用_source属性中设置 过滤结果。

新增修改
PUT /test/prodect/1
{
  "name":"冰箱海尔"
}

如果添加未定义的字段 es会自动创建字段 并判断类型
如果存储的是string类型数据,es无法智能判断,他就会存两个字段。
例如:

  • name:text类型
  • name.keyword:keyword类型
删除
DELETE /test/prodect/1
查询

GET /test/prodect/1

 GET /test/_search
    {
      "query": {"match_all": {}}
    }

match_all查所有
match全文检索查询
模糊匹配or 只要分词匹配就展示

GET /test/_search
    {
      "query": {"match": {
        "name": "冰箱2"
      }}
    }

完全匹配and 所有匹配才展示

  GET /test/_search{
   "query": {"match": {
     "name": {"": "冰箱2","operator": "and"}
   }}
 }  

匹配度

    GET /test/_search{
      "query": {"match": {
        "name": {"query": "冰箱2","minimum_should_match": "75%"}
      }}
    }

多字段查询(multi_match)

    GET /test/_search{
      "query": {
          "multi_match": {
              "query": "冰箱2",
              "fields": ["title","name"]
          }
      }
    }

range范围
term词条匹配 不分词查询 精确匹配

    GET /test/_search{
      "query": {
          "term": {
            "name":  "冰箱2"
          }
      }
    }

_source 结果过滤

GET /test/_search
{
  "_source": "name", 
  "query": {"match": { "name": {"query": "冰箱2","operator": "and"}
  }}
}

filter 过滤条件

聚合统计

GET /company/_search
{
  "size": 1,
  "aggs": {
    "popularName": {
      "terms": {
        "field":"age"
      }
    }
  }
}
GET /company/_search
{
  "size": 1,
  "aggs": {
    "popularName": {
      "terms": {
        "field":"age"
      },"aggs": {
        "sumName": {
          "sum": {
            "field":"price"
          }
        }
      }
    }
  }
}

分词器
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值