ElasticSearch教程——Kibana简单操作ES-程序员宅基地

技术标签: Kibana  ElasticSearch从入门到精通再到深入剖析  ElasticSearch  Kibana 工具  elasticsearch Kibana  

ElasticSearch汇总请查看ElasticSearch教程——汇总篇

运行、打开kibana相关工具

要先运行ElasticSearch

/usr/elasticsearch/kibana/kibana-6.4.0-linux-x86_64/bin
sh kibana

打开对应的dev Tools

 

获取所有数据

GET /_search

返回结果

{
  "took": 76,
  "timed_out": false,
  "_shards": {
    "total": 16,
    "successful": 16,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 8,
    "max_score": 1,
    "hits": [
      {
        "_index": ".kibana",
        "_type": "doc",
        "_id": "config:6.4.0",
        "_score": 1,
        "_source": {
          "type": "config",
          "updated_at": "2018-09-18T09:30:18.949Z",
          "config": {
            "buildNum": 17929,
            "telemetry:optIn": true
          }
        }
      },
      {
        "_index": "blog",
        "_type": "article",
        "_id": "eTmX5mUBtZGWutGW0TNs",
        "_score": 1,
        "_source": {
          "title": "New version of Elasticsearch released!",
          "content": "Version 1.0 released today!",
          "priority": 10,
          "tags": [
            "announce",
            "elasticsearch",
            "release"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "jiajieshi yagao",
          "desc": "youxiao fangzhu",
          "price": 25,
          "producer": "jiajieshi producer",
          "tags": [
            "fangzhu"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "J3fLFWYBBoLynJN1-kOG",
        "_score": 1,
        "_source": {
          "name": "test yagao",
          "desc": "youxiao fangzhu"
        }
      },
      {
        "_index": "blog",
        "_type": "article",
        "_id": "1",
        "_score": 1,
        "_source": {
          "id": "1",
          "title": "New version of Elasticsearch released!",
          "content": "Version 1.0 released today!",
          "priority": 10,
          "tags": [
            "announce",
            "elasticsearch",
            "release"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "KXfSFWYBBoLynJN1TUPo",
        "_score": 1,
        "_source": {
          "name": "test yagao2",
          "desc": "youxiao fangzhu2"
        }
      },
      {
        "_index": "index",
        "_type": "fulltext",
        "_id": "1",
        "_score": 1,
        "_source": {
          "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "zhonghua yagao",
          "desc": "caoben zhiwu",
          "price": 40,
          "producer": "zhonghua producer",
          "tags": [
            "qingxin"
          ]
        }
      }
    ]
  }
}

 

返回数据含义

 

took:耗费了几毫秒
timed_out:是否超时,false是没有,默认无timeout
_shards:shards fail的条件(primary和replica全部挂掉),不影响其他shard。默认情况下来说,一个搜索请求,会打到一个index的所有primary shard上去,当然了,每个primary shard都可能会有一个或多个replic shard,所以请求也可以到primary shard的其中一个replica shard上去。
hits.total:本次搜索,返回了几条结果
hits.max_score:score的含义,就是document对于一个search的相关度的匹配分数,越相关,就越匹配,分数也高
hits.hits:包含了匹配搜索的document的详细数据,默认查询前10条数据,按_score降序排序

timeout这边默认是没有的,也就意味着当你搜索的时候他会直到所有搜索结束才会返回结果,但是当我们做一些时间比较敏感的搜索的时候,等待时间很久,对用户来说是非常不友好的。那我们可以通过设置timeout这个值,来定时返回已经搜索到的数据。timeout机制,指定每个shard,就只能在timeout时间范围内,将搜索到的部分数据(也可能是搜索到的全部数据),直接返回给client,而不是等到所有数据全部搜索出来后再返回。

可以通过如下方式进行设置

timeout=10ms,timeout=1s,timeout=1m
GET /_search?timeout=10m

 

 

创建Document

PUT /ecommerce/product/1
{
    "name" : "gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}
PUT /ecommerce/product/2
{
    "name" : "jiajieshi yagao",
    "desc" :  "youxiao fangzhu",
    "price" :  25,
    "producer" :      "jiajieshi producer",
    "tags": [ "fangzhu" ]
}
PUT /ecommerce/product/3
{
    "name" : "zhonghua yagao",
    "desc" :  "caoben zhiwu",
    "price" :  40,
    "producer" :      "zhonghua producer",
    "tags": [ "qingxin" ]
}

检索文档(查询)

GET /ecommerce/product/1

返回结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "name": "gaolujie yagao",
    "desc": "gaoxiao meibai",
    "price": 30,
    "producer": "gaolujie producer",
    "tags": [
      "meibai",
      "fangzhu"
    ]
  }
}

替换文档(全量替换)

PUT /ecommerce/product/1
{
    "name" : "jiaqiangban gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}

返回结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 2,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 1,
  "_primary_term": 1
}

document结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "name": "jiaqiangban gaolujie yagao"
  }
}

注意点

  1. document是不可变的,如果要修改document的内容,可以通过全量替换,直接对document重新建立索引,替换里面所有的内容。
  2. es会将老的document标记为deleted(逻辑删除),然后新增我们给定的一个document,当我们创建越来越多的document的时候,es会在适当的时机在后台自动删除(物理删除)标记为deleted的document。
  3. 替换必须带上所有的field,否则其他数据会丢失。

 

 

更新文档(修改)

原理参考:ElasticSearch教程——partial update(更新文档)实现原理及并发控制

POST /ecommerce/product/1/_update
{
  "doc": {
    "name": "jiaqiangban gaolujie yagao"
  }
}

返回结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 5,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 4,
  "_primary_term": 1
}

document结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 5,
  "found": true,
  "_source": {
    "name": "jiaqiangban gaolujie yagao",
    "desc": "gaoxiao meibai",
    "price": 30,
    "producer": "gaolujie producer",
    "tags": [
      "meibai",
      "fangzhu"
    ]
  }
}

 

 

删除文档(删除)

DELETE /ecommerce/product/1

返回结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 9,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 8,
  "_primary_term": 1
}

document结果

{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "found": false
}

注意:

在删除一个document之后,我们可以从侧面证明,它不是立即物理删除的,因为它的一些版本号等信息还是保留的。

 

请求分类

1、query string search

类似这种 搜索全部商品:GET /ecommerce/product/_search(参数直接拼接在请求url上,不带json参数的)

query string search的由来,因为search参数都是以http请求的query string来附带的

搜索商品名称中包含yagao的商品,而且按照售价降序排序:GET /ecommerce/product/_search?q=name:yagao&sort=price:desc

适用于临时的在命令行使用一些工具,比如curl,快速的发出请求,来检索想要的信息;但是如果查询请求很复杂,是很难去构建的,所以在生产环境中,几乎很少使用query string search

 

2、query DSL

DSL:Domain Specified Language,特定领域的语言
http request body:请求体,可以用json的格式来构建查询语法,比较方便,可以构建各种复杂的语法,比query string search肯定强大多了。

更加适合生产环境的使用,可以构建复杂的查询

1.查询所有的商品

GET /ecommerce/product/_search
{
  "query": { "match_all": {} }
}

 

2.查询名称包含yagao的商品,同时按照价格降序排序

GET /ecommerce/product/_search
{
    "query" : {
        "match" : {
            "name" : "yagao"
        }
    },
    "sort": [
        { "price": "desc" }
    ]
}

 

3.分页查询

总共3条商品,假设每页就显示1条商品,现在显示第2页,所以就查出来第2个商品

GET /ecommerce/product/_search
{
  "query": { "match_all": {} },
  "from": 1,
  "size": 1
}

 

4.查询指定项

指定要查询出来商品的名称和价格

GET /ecommerce/product/_search
{
  "query": { "match_all": {} },
  "_source": ["name", "price"]
}

 

 

5.过滤查询

搜索商品名称包含yagao,而且售价大于25元的商品

GET /ecommerce/product/_search
{
    "query" : {
        "bool" : {
            "must" : {
                "match" : {
                    "name" : "yagao" 
                }
            },
            "filter" : {
                "range" : {
                    "price" : { "gt" : 25 } 
                }
            }
        }
    }
}

 

6.full-text search(全文检索)

GET /ecommerce/product/_search
{
    "query" : {
        "match" : {
            "producer" : "yagao producer"
        }
    }
}

7.phrase search(短语搜索)

跟全文检索相对应,相反,全文检索会将输入的搜索串拆解开来,去倒排索引里面去一一匹配,只要能匹配上任意一个拆解后的单词,就可以作为结果返回
phrase search,要求输入的搜索串,必须在指定的字段文本中,完全包含一模一样的,才可以算匹配,才能作为结果返回

GET /ecommerce/product/_search
{
    "query" : {
        "match_phrase" : {
            "producer" : "yagao producer"
        }
    }
}

 

8.多条件查询

名字中有"yagao",描述上可以有fangzhu也可以没有,价格不能是25元

must表示一定要满足;

should表示可以满足也可以不满足;

must_not表示不能满足该条件;

"minimum_should_match": 1,表示最小匹配度,可以设置为百分百,详情看源文档Elasticsearch Reference [6.4] » Query DSL » Minimum Should Match,设置了这个值的时候就必须满足should里面的设置了,另外注意这边should里面同一字段设置的多个值(意思是当这个值等于X或者等于Y的时候都成立,务必注意格式

 

GET /ecommerce/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "yagao"
          }
        }
      ],
      "should": [
        {
          "match": {
            "desc": "fangzhu"
          }
        },
        {
          "match": {
            "desc": "caoben"
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "price": 25
          }
        }
      ],
     "minimum_should_match": 1
    }
  }
}

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/gwd1154978352/article/details/82804942

智能推荐

JavaScript中Blob对象及示例_res.blob()-程序员宅基地

文章浏览阅读810次。Blob(binary large object)是计算机界通用术语之一,表示二进制大对象。在JavaScript中,Blob通常表示二进制数据,不过,它们不一定非得是大量数据,Blob也可以表示一个小型文本文件的内容_res.blob()

【Greenplum 6.9.0】Greenplum Command Center 6.2安装失败教程_greenplum command center无法下载-程序员宅基地

文章浏览阅读2k次。需要这个?gpperfmon_install --enable --password gpmon --port 5432-bash: gpperfmon_install: command not found直接安装?unzip gpcc.zip报错Failed to connect to database postgres on 127.0.0.1:5432 as gpadmin: libgssapi_krb5.so: cannot open shared object file: No s_greenplum command center无法下载

基于LVDS的高速自同步串行传输系统的研究_lvds总线-程序员宅基地

文章浏览阅读1.5k次,点赞2次,收藏8次。本文从高速数据传输的需求出发,对高速串行LVDS(Low Voltage Differential Signaling,低压差分信号)接口电路进行研究,重点对其传输方式进行了研究分析。基于SER/DES(Serial/Deserializer,串行/解串器)设计构架下,提出了高速自同步串行传输系统的实现方法。0 引言随着信息技术的日新月异,传统的I/O接口无法满足越来越大的数据处理任务。相对于串行传输技术,采取并行传输技术,提高通道数量就能提高数据传输数率,但是会增加很多成本。而且,并行传输技术中存在_lvds总线

vs2010和Matlab R2012a 混合编程_matlabr2012a怎么运行代码-程序员宅基地

文章浏览阅读1.7k次。转自:http://blog.sina.com.cn/s/blog_4fc6546101011cu5.html本人系统Windows 7旗舰版,32位,采用由m文件构造动态链接库然后在visual studio中调用的方法。1. MATLAB 环境配置: 注:Matlab r2010b及以后版本才支持vs2010, 之前版本中mbuild命令输入后可能会_matlabr2012a怎么运行代码

分治法之合并排序(2021/1/23)_分治法合并程序-程序员宅基地

文章浏览阅读247次。问题引入代码实现#include<iostream>#include<cstdlib>using namespace std;struct Data{ int flag;};void MergeFunction(struct Data*list,int low,int middle,int high){ //申请辅助空间 int size=high-low; struct Data*space=(struct Data*)malloc(sizeof(struc_分治法合并程序

正规文法构造状态转换图,状态转换图构造正规文法---编译原理_文法状态图-程序员宅基地

文章浏览阅读7.9k次,点赞19次,收藏104次。从左线性正规文法出发,构造状态图注意:增设初态S,单圆圈表示例子从右线性正规文法出发,构造状态图注意:增设终态Z,双圆圈表示例子状态转换图构造左线性正规文法注意:写左线性正规文法时从终态开始例子状态转换图构造右线性正规文法注意:写右线性正规文法时从初态开始例子..._文法状态图

随便推点

安全多方计算中通用混淆电路估值技术_电路估值密码学-程序员宅基地

文章浏览阅读218次。总序广义上而言SMPC分为两种实现方式,一类是使用布尔电路表述待计算函数,然后使用通用混淆电路来实现安全多方计算。另一类是使用域上的算术电路表述待计算函数,然后使用密码学方法实现安全多方计算。Yao氏混淆电路估值方案该方案可以用于实现对任何类型的门电路的安全估值。Lindell和Pinkas对该方案进行了严格的安全论证,证明该方案在半诚实模型下是安全的。下面简介姚氏混淆电路估值方案。令$C..._电路估值密码学

中文语义匹配_from eval import evaluate-程序员宅基地

文章浏览阅读533次。中文语义匹配_from eval import evaluate

Linux 查看 每个 cpu 的核心数_命令行 为什么查看每个cpu的核数不需要加 wc -l-程序员宅基地

文章浏览阅读3w次。Linux 查看 每个 cpu 的核心数cat /proc/cpuinfo | grep "processor" | grep "0" | wc -l_命令行 为什么查看每个cpu的核数不需要加 wc -l

解决 LINK : fatal error LNK1158: cannot run ‘rc.exe‘_qt cannot run rc.exe-程序员宅基地

文章浏览阅读1k次。问题安装 mmcv时报错 LINK : fatal error LNK1158: cannot run ‘rc.exe’原因这是找不到rc.exe导致问题解决措施在 C:\Program Files (x86)\Windows Kits\8.1\bin\x86 下找到rcdll.dll 和rc.exe复制到VC安装路径中,我的是 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin再次运行,安装成功Looking in inde_qt cannot run rc.exe

WPS宏开发之VBA宏转JS宏_vba转js-程序员宅基地

文章浏览阅读9.2k次,点赞10次,收藏78次。WPS宏开发 VBA宏转JS宏_vba转js

Pytorch:Pytorch升级版本1.1(支持TensorBoard)的简介、安装、使用方法之详细攻略_pytorch升级到1.1-程序员宅基地

文章浏览阅读9.7k次,点赞5次,收藏18次。Pytorch:Pytorch升级版本1.1(支持TensorBoard)的简介、安装、使用方法之详细攻略目录Pytorch1.1的简介1、支持TensorBoard:torch.utils.tensorboardPytorch1.1的安装pipPytorch1.1的使用方法Pytorch1.1的简介 选择您的首选项并运行..._pytorch升级到1.1

推荐文章

热门文章

相关标签