elasticsearch-kibana环境搭建

一. elasticsearch环境搭建

  1. 复制elasticsearch-7.7.0-amd64.deb到服务器~/soft目录下
  2. 使用命令sudo dpkg -i elasticsearch-7.7.0-amd64.deb安装
  3. *可以查看安装目录在/usr/share/elasticsearch
  4. *可以查看配置文件在目录/etc/elasticsearch/elasticsearch.yml
  5. 修改配置文件sudo vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
  1. 启动elasticsearch服务service elasticsearch start
  2. 浏览器输入http://localhost:9200即可查看

二. kibana环境搭建

  1. 复制kibana-7.7.0-amd64.deb到服务器~/soft目录下
  2. 使用命令sudo dpkg -i kibana-7.7.0-amd64.deb安装
  3. *可以查看安装目录在/usr/share/kibana
  4. *可以查看配置文件在目录/etc/elasticsearch/kibana.yml
  5. 修改配置文件sudo vi /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
il8n.locale: "zh-CN"

三. 使用kibana操作elasticsearch

# 1.创建索引
PUT test1
# 2.查看索引
GET _cat/indices
# 3.删除索引
DELETE test1
# 4.添加数据
PUT test1/_doc/1
{
  "name":"大壮",
  "age":18,
  "location":"北京"
}
# 5.查看数据
GET test1/_doc/1
# 6.查看索引内所有数据
GET test1/_search
# 7.更新数据
POST test1/_update/1
{
  "doc": {
    "location": "北京市朝阳区"
  }
}
# 8.删除数据
DELETE test1/_doc/1
# 9.简单查询
GET test1/_search?q=location="广州"
# 10.使用DSL语句进行查询
# location text 分词,以or的形式匹配
# location.keyword,不分词
GET test1/_search
{
  "query": {
    "match": {
      "location.keyword": "广州"
    }
  }
}
# 11.select * from tables
GET test1/_search
{
  "query": {
    "match_all": {}
  }
}
# 12.按age排序
GET test1/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ]
}
# 13.分页,从索引为1开始,查询两条
GET test1/_search
{
  "query": {
    "match_all": {}
  },
  "from": 1,
  "size": 2
}  
# 14.bool查询 not and or
GET test1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "location.keyword": "广州"
          }
        }
      ], 
      "should": [
        {
          "match": {
            "age": 20
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "name": "李四"
          }
        }
      ],
      "filter": [
        {
          "range": {
            "age": {
              "gt": 10,
              "lte": 20
            }
          }
        }
      ]
    }
  }
}
# 15.结果过滤
GET test1/_search
{
  "_source": "name"
}
# 16.高亮显示
GET test1/_search
{
  "query": {
    "match": {
      "location": "广州"
    }
  },
  "highlight": {
    "pre_tags": "<b style='color: red'>",
    "post_tags": "</b>", 
    "fields": {
      "location": {}
    }
  }
}
# 17. 聚合函数
GET test1/_search
{
  "query": {
    "match": {
      "location.keyword": "广州"
    }
  },
  "aggs": {
    "agg_avg": {
      "avg": {
        "field": "age"
      }
    }
  },
 "_source": ["name", "age"]
}
# 18.分组查询
GET test1/_search
{
  "size": 0, 
  "query": {
    "match_all": {}
  },
  "aggs": {
    "age_group": {
      "range": {
        "field": "age",
        "ranges": [
          {
            "from": 10,
            "to": 20
          },
          {
            "from": 20,
            "to": 30
          }
        ]
      }
      , "aggs": {
        "age_avg": {
          "avg": {
            "field": "age"
          }
        }
      }
    }
  }
}
  • 安装ik分词器sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.7.0/elasticsearch-analysis-ik-7.7.0.zip
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值