zoukankan      html  css  js  c++  java
  • 016-插件使用-head

    一、安装以及概览

    elasticsearch-head将是一款专门针对于elasticsearch的客户端工具

    elasticsearch-head配置包,下载地址:https://github.com/mobz/elasticsearch-head   git地址:https://github.com/mobz/elasticsearch-head.git

    elasticsearch-head是一个基于node.js的前端工程,启动elasticsearch-head的步骤如下:https://www.cnblogs.com/bjlhx/p/8494555.html

     在浏览器访问http://localhost:9100,或者file:///D:/Code/elasticsearch-head/_site/index.html 可看到如下界面,表示启动成功:

    集群健康值的几种状态如下:

         绿色,最健康的状态,代表所有的分片包括备份都可用

        黄色,基本的分片可用,但是备份不可用(也可能是没有备份)

           红色,部分的分片可用,表明分片有一部分损坏。此时执行查询部分数据仍然可以查到,遇到这种情况,还是赶快解决比较好

             灰色,未连接到elasticsearch服务

    1.1、概览

      

      通过上图可以看到我们的节点名称为elasticsearch,并且该节点下有两个索引test_index1、test_index2

      在test_index2下,选择信息-->索引信息,可以查看该索引的所有信息,包括mappings、setting等等

        

      在test_index2下,选择动作-->关闭/开启,可以关闭/开启该索引,关闭后的索引如图:

        

    1.2、索引

     在这里,可以查看到所以的索引,并且还可以创建一个新的索引,如下图:

      

    1.3、数据浏览

      这里可看到索引、类型、字段、数据信息,如下图所示:

      

    1.4、基本查询

      在这个页签,可以做数据进项简单的查询:

      

      选择一个索引,然后再选择不同的查询条件,勾选“显示查询语句”,最后点击搜索,可以看到具体的查询json和查询结果

     1.5、复合查询

      在这个页签,可以使用json进行复杂的查询,也可发送put请求新增及跟新索引,使用delete请求删除索引等等。如图所示:

      

      

      查询前两行为url参数,中间部分为请求参数

    二、复合查询

    2.1、查看集群信息

    示例,查看集群健康:GET /_cat/nodes?v

      

      https://www.elastic.co/guide/en/elasticsearch/reference/5.4/gs-cluster-health.html

    更多命令:命令结构:<REST Verb> /<Index>/<Type>/<ID>

    查看集群健康:GET /_cat/nodes?v

    查看所有索引:GET /_cat/indices?v

    创建索引:PUT /customer?pretty

    添加数据【指定ID增加】

    PUT /customer/external/1?pretty
    {
      "name": "John Doe"
    }

    添加数据【不指定ID,随机ID,如果put不指定ID会报错】

    POST /customer/external?pretty
    {
      "name": "Jane Doe"
    }

    查看数据

    GET /customer/external/1?pretty

    删除索引

    DELETE /customer?pretty

    修改数据【同增加一致,但是ID要一样才是修改,否则是 添加】

    更新文档

    POST /customer/external/1/_update?pretty
    {
      "doc": { "name": "Jane Doe" }
    }

      或者

    POST /customer/external/1/_update?pretty
    {
      "doc": { "name": "Jane Doe", "age": 20 }
    }

    删除文档

    DELETE /customer/external/2?pretty

    批量处理

    POST /customer/external/_bulk?pretty
    {"index":{"_id":"1"}}
    {"name": "John Doe" }
    {"index":{"_id":"2"}}
    {"name": "Jane Doe" }

      或者

    POST /customer/external/_bulk?pretty
    {"update":{"_id":"1"}}
    {"doc": { "name": "John Doe becomes Jane Doe" } }
    {"delete":{"_id":"2"}}

    2.2、查看mapping

      /customer_index/_mapping/external_type/

    2.3、搜索API

    GET /bank/_search?q=*&sort=account_number:asc&pretty

    说明:bank 是索引、_search 是搜索端点、q=* 是所有字段、sort=account_number:asc 是按照account_num升序

    针对返回值:

    {
      "took" : 63,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 1000,
        "max_score" : null,
        "hits" : [ {
          "_index" : "bank",
          "_type" : "account",
          "_id" : "0",
          "sort": [0],
          "_score" : null,
          "_source" : {"account_number":0,"balance":16623,"firstname":"Bradshaw","lastname":"Mckenzie","age":29,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"bradshawmckenzie@euron.com","city":"Hobucken","state":"CO"}
        }, {
          "_index" : "bank",
          "_type" : "account",
          "_id" : "1",
          "sort": [1],
          "_score" : null,
          "_source" : {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
        }, ...
        ]
      }
    }
    View Code

    说明:took 查询耗时 毫秒

    当然上述也可以转换成

    GET /bank/_search
    {
      "query": { "match_all": {} },
      "sort": [
        { "account_number": "asc" }
      ]
    }

    更多查询命令:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/indices.html

    2.4、别名

    查看:GET /_alias

    增加 

    POST /_aliases
    {
        "actions" : [
            { "add" : { "index" : "test1", "alias" : "alias1" } }
        ]
    }

    更多:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/indices-aliases.html 

      

  • 相关阅读:
    1219
    hdu 1280 前m大的数 和 hdu 4223 Dynamic Programming?
    codeforces Lucky Sum
    20121028
    asp.net(c#) 取得网卡mac地址
    代码使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图
    SQL Server日志文件总结及日志满的处理
    服务器应用程序不可用解决方案集
    如何调用存储过程,有返回值的,有参数的,存储过程中调用存储过程。(MS SQL Server)
    让网页自动刷新
  • 原文地址:https://www.cnblogs.com/bjlhx/p/10518579.html
Copyright © 2011-2022 走看看