当前位置:网站首页>kibana操作es
kibana操作es
2022-07-25 14:32:00 【你就像甜甜的益达】
文章目录
es初探
es官网介绍
kibana操作es
Elaticsearch,简称为es,对es的操作都是基于REST风格的操作;
基本的操作有:PUT(创建,修改) POST(创建,修改) DELETE(删除) GET(查询) POST(查询) ;就是我们平常干的最多的增删改查;查询是最主要最复杂的.
我贴的都是可以直接复制到kibana里面的,然后数据的大家可以自己多造一点,可以自己根据查询的造.
简单操作
# 获取ElasticSearch的当前的很多信息!
GET _cat/
GET /_cat/plugins
## 分词
GET _analyze
{
"analyzer": "ik_smart",
"text": "年轻人不讲武德"
}
GET _analyze
{
"analyzer": "ik_max_word",
"text": "年轻人不讲武德"
}
# 创建索引,创建过后不能修改
PUT /test1
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
},
"tag":{
"type": "text"
}
}
}
}
# 获取索引信息
GET test1
## 删除索引
DELETE test1
# 新增文档 指定id,跟随机id
PUT /test1/_doc/1
{
"name":"张益达",
"age":11,
"birthday": "1990-08-09"
}
POST /test1/_doc/
{
"name":"张益达",
"age":11,
"birthday": "1990-08-09"
}
# 修改文档
# put覆盖,_version会+1 如果不传为空(不建议,会丢失字段,除非确实想全部覆盖)
PUT /test1/_doc/1
{
"name" : "张益达",
"age" : 183
}
GET /test1/_doc/1
# post _update 建议,_version不变(建议,注意doc字段)
POST /test1/_update/1/
{
"doc": {
"name" : "张益达2"
}
}
GET /test1/_doc/1
查询操作
查询基本操作
## 查询
## Deprecation: [types removal] Specifying types in search requests is deprecated.会让你删掉type,_doc
GET /test1/_doc/_search?q=name:益
GET /test1/_search?q=name:益
GET /test1/_search?q=age:11
##查询匹配
##match:匹配(会使用分词器解析(先分析文档,然后进行查询))
## term: 直接通过倒排索引指定词条,精准查询,不进行分词,适合的字段类型有number,date,keyword,不适合text
##_source:过滤字段
##sort:排序
##form、size 分页
GET /test1/_search
{
"query": {
"match": {
"name": "张"
}
}
,
"_source": ["name","age"],
"sort": [
{
"age": {
"order": "asc"
}
}
],
"from": 1
,
"size": 1
}
# 多条件查询
#must 相当于 and
#should 相当于 or
#must_not 相当于 not (... and ...)
#filter 过滤
GET /test1/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "1"
}
},
{
"match": {
"age": "1"
}
}
],
"filter": [
{
"range": {
"age": {
"gte": 1,
"lte": 2
}
}
}
]
}
}
}
# 创建带数组的索引,索引不存在会自动创建
POST /test_arr/_doc
{
"name" : "张益达2",
"age" : 18,
"birthday":"1990-09-08",
"tag":["律师","搞笑","自信"]
}
POST /test_arr/_doc
{
"name" : "张益达3",
"age" : 18,
"birthday":"1990-09-08",
"tag":["律师" ,"男"]
}
GET /test_arr/_doc/1
GET /test_arr/_search
{
"query": {
"match": {
"tag": "男 师"
}
}
}
# match 会使用分词器解析(先分析文档,然后进行查询)
GET /test_arr/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "张"
}
},
{
"match": {
"tag": "男律师搞笑女自信人"
}
}
]
}
}
}
# term精准查询
GET /test1/_search
{
"query": {
"term": {
"age": 1
}
}
}
text和keyword
- text:
支持分词,全文检索、支持模糊、精确查询,不支持聚合,排序操作;
text类型的最大支持的字符长度无限制,适合大字段存储; - keyword:
不进行分词,直接索引、支持模糊、支持精确匹配,支持聚合、排序操作。
keyword类型的最大支持的长度为——32766个UTF-8类型的字符,可以通过设置ignore_above指定自持字符长度,超过给定长度后的数据将不被索引,无法通过term精确匹配检索返回结果。
## 测试keyword和text是否支持分词
PUT /test
{
"mappings": {
"properties": {
"text":{
"type":"text"
},
"keyword":{
"type":"keyword"
}
}
}
}
PUT /test/_doc/1
{
"text":"测试keyword和text是否支持分词",
"keyword":"测试keyword和text是否支持分词"
}
# text 支持分词
# keyword 不支持分词
# 查得到
GET /test/_doc/_search
{
"query":{
"match":{
"text":"测试"
}
}
}
## 查不到
GET /test/_doc/_search
{
"query":{
"match":{
"keyword":"测试"
}
}
}
# 分词分析
GET _analyze
{
"analyzer": "keyword",
"text": ["测试liu"]
}
GET _analyze
{
"analyzer": "standard",
"text": ["测试liu"]
}
GET _analyze
{
"analyzer":"ik_max_word",
"text": ["测试liu"]
}
高亮查询
## 高亮查询,主要就是在查询的内容加前缀后缀
GET test1/_doc/_search
{
"query": {
"match": {
"name":"张"
}
}
,
"highlight": {
"pre_tags": "<p class='key' style='color:red'>",
"post_tags": "</p>",
"fields": {
"name": {
}
}
}
}
至此kibana操作es的一些常用操作就完成,更详细的可以看官方文档:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/full-body-search.html
下一节使用java代码操作es
边栏推荐
- Under the epidemic, the biomedical industry may usher in breakthrough development
- Thymeleaf controls whether display is displayed through style
- Nuc980 set up SSH xshell connection
- 物理量与单位符号的书写标准
- Teach you how to apply for SSL certificate
- pt100测温电路图(ad590典型的测温电路)
- PS制作加载GIF图片教程
- Wechat official account official environment online deployment, third-party public platform access
- VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
- Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
猜你喜欢

sqli-labs Basic Challenges Less1-10
![优质数对的数目[位运算特点+抽象能力考察+分组快速统计]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
优质数对的数目[位运算特点+抽象能力考察+分组快速统计]

~4.1 sword finger offer 05. replace spaces

阿里云安装MYSQL5.7

基于redis的keys、scan删除ttl为-1的key

DVWA practice - brute force cracking

English语法_不定代词 - other / another

~5 new solution of CCF 2021-12-2 sequence query

Melodic + Realsense D435i 配置及错误问题解决

安防市场进入万亿时代,安防B2B网上商城平台精准对接深化企业发展路径
随机推荐
SSH服务器拒绝了密码
IDEA报错 Failed to determine a suitable driver class
Bond0 script
C language and SQL Server database technology
元器件采购系统的主要功能,数字化采购助力元器件企业飞速发展
Teach you how to apply for SSL certificate
awk从入门到入土(24)提取指令网卡的ip
pt100测温电路图(ad590典型的测温电路)
Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders
PS making and loading GIF pictures tutorial
Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
Niuke multi school E G J L
Famous handwritten note taking software recruit CTO · coordinate Shenzhen
Matplotlib data visualization three minutes entry, half an hour enchanted?
Jqgrid select all cancel single line click cancel event
Typora无法打开提示安装新版本解决办法
实现一个家庭安防与环境监测系统(一)
Ten common application scenarios of redis
filters获取data中的数据;filters使用data中的数据
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction