kibana的安装和es的使用

在官网下载完kibana(以上篇版本为主v7.3.0)

查看kibana配置

# kibana的默认端口
#server.port: 5601

# 主机地址 填入localhost
server.host: "localhost"
 # 请求体最大值
#server.maxPayloadBytes: 1048576

#服务名
server.name: "choviwu"

#es的节点,多个用逗好隔开
#elasticsearch.hosts: ["http://localhost:9200"]

# When this setting's value is true Kibana uses the hostname specified in the server.host
# setting. When the value of this setting is false, Kibana uses the hostname of the host
# that connects to this Kibana instance.
#elasticsearch.preserveHost: true

# kibana 创建默认的索引
# dashboards. Kibana creates a new index if the index doesn't already exist.
#kibana.index: ".kibana"

# 默认的appid
#kibana.defaultAppId: "home"
 
# 访问es的账号密码
#elasticsearch.username: "kibana"
#elasticsearch.password: "pass"
#底下是https的一些配置
# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
#server.ssl.enabled: false
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key
...
#elasticsearch.ssl.verificationMode: full

# ping es的超时时间
#elasticsearch.pingTimeout: 1500

# es 请求时间
elasticsearch.requestTimeout: 30000

# List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
# headers, set this value to [] (an empty list).
#elasticsearch.requestHeadersWhitelist: [ authorization ]

# Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
# by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
#elasticsearch.customHeaders: {}

# Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
elasticsearch.shardTimeout: 30000

# Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying.
elasticsearch.startupTimeout: 5000

# Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
elasticsearch.logQueries: true

# Set the value of this setting to true to log all events, including system usage information
# and all requests.
logging.verbose: true

# Set the interval in milliseconds to sample system and process performance
# metrics. Minimum is 100ms. Defaults to 5000.
#ops.interval: 5000

#  国际化支持,默认是en  可以该成zh-CN  
# Supported languages are the following: English - en , by default , Chinese - zh-CN . 
i18n.locale: "zh-CN"

启动kibana

双击执行bin目录下的kibana.bat/kibana

打开之后可以看到kibana的界面

image.png

点击左下角标红的 开发工具,然后执行相应的命令

1、创建索引(类似于创建数据库):

PUT order

2、创建文档:

PUT order/_doc/1
{
  "orderNo": "B112943294823984T12483",
  "orderId": 19434852,
  "userId": "djsifjfvxh23hsdhuasxhsdfv0",
  "payTime": 1611065280000
}

服务端的响应:

{
  "_index" : "order",  # 索引值
  "_type" : "_doc",    # 类型 doc类型  老版本需要标识type
  "_id" : "1",         # id 文档的id
  "_version" : 1,      #版本号,从1开始,如果更新则version+1
  "result" : "created", # 创建 后面还有updated
  "_shards" : {
    "total" : 2,       
    "successful" : 1,  # 成功
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

然后再执行一遍上面的命令得到

{
  "_index" : "order",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 2,        # 可以看到版本号+1
  "result" : "updated",  #这里也是更新
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}

如果id设置为2呢? 没错,如果是2的话,服务端查询没有这个id,则会新建一条文档,反之update。

查询

term查询

term query,就是精确匹配,执行下面的json则会查询到相应的内容,如果value值有任意一个字符不匹配则不会命中文档

GET order/_search
{
  "query": {
    "term": {
      "orderId": {
        "value": 19434852
      }
    }
  }
}

bool查询

Bool查询对应Lucene中的BooleanQuery,它由一个或者多个子句组成,每个子句都有特定的类型,就像下面那条json,我整理了一下写到了下面表格中

mustfiltershouldmust_nout
返回的文档必须满足must子句的条件,并且参与计算分值返回的文档必须满足filter子句的条件。但是不会像Must一样,参与计算分值返回的文档可能满足should子句的条件。在一个Bool查询中,如果没有must或者filter,有一个或者多个should子句,那么只要满足一个就可以返回返回的文档必须不满足must_not定义的条件

其实这些完全可以从单词字义上可以帮助理解每个类型的功能,must是必须匹配数组下的所有条件才可以,filter为过滤当前匹配的, should为满足其中一个
即可,must_nout是不满足这个条件

GET order/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "orderId": {
              "value": "19434852"
            }
          }
        }
      ],
      "filter": {
        "term": {
          "orderNo": "B112943294823984T12483"
        }
      },
      "should": [
        {
          "match": {
            "orderId": "19434852"
          }
        }
      ]
    }
  }
}
# 教程   搜索  

评论

公众号:mumuser

企鹅群:932154986

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×