zoukankan      html  css  js  c++  java
  • Elasticsearch-Head基本使用方法

    一、创建索引index和mapping

    可参考https://www.cnblogs.com/wenbronk/p/9395861.html

    (1)

    请求方式:PUT

    路径输入框:索引名

    内容输入框:

    {
      "mappings": {
        "_doc": {
          "properties": {
            "args": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "result": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "method": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "createTime": {
              "format": "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis",
              "type": "date"
            },
            "takeTime": {
              "type": "long"
            },
            "appId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "groupId": {
              "type": "long"
            },
            "resultSize": {
              "type": "long"
            },
            "id": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "interfaceName": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "interfaceCode": {
              "type": "text",
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            }
          }
        }
      }
    }

    二、删除索引

    (1)删除单个索引

    请求方式:DELETE

    路径输入框:/索引名

    内容输入框默认

    (2)删除多个索引

    请求方式:DELETE

    路径输入框:/索引名1,索引名2

    内容输入框默认

    (3)删除以XX开头的所有索引文件(删除以testindex 开头的所有索引文件,如配置文件禁止此方式后不能使用)

    请求方式:DELETE

    路径输入框:/testindex*

    内容输入框默认

    (4)删除全部索引(如配置文件禁止此方式后不能使用)

    请求方式:DELETE

    路径输入框: /_all

    内容输入框默认

    三、插入数据

    (1)查看表结构,概览-索引信息,mappings下的第一个字段关键字,即是文档名称_doc

    (2)复合查询-查询,插入数据

    请求方式:POST

    路径输入框:索引名称/文档名称/主键编号,例:testindex/_doc/1200001

    内容输入框:填入

    {
        "args":"xx",
        "result":"xx",
        "method":"xx",
        "createTime":"2019/05/08 16:26:49",
        "takeTime":"2019/05/08 16:26:49",
        "appId":"xxxxxx",
        "groupId":"1",
        "resultSize":"100",
        "id":"1",
        "interfaceName":"接口名称",
        "interfaceCode":"abc"
    }

    四、删除数据

    (1)据主键删除数据

    请求方式:DELETE,路径输入框:/索引名称/文档名称/主键编号,内容输入框默认{"query":{"match_all":{}}}

    (2)据匹配条件删除数据(该过程没有回滚,只有中断)

    请求方式:POST,路径输入框:索引名称/文档名称/_delete_by_query,内容输入框填搜索条件

    例1:匹配具体用户 例: { "query":{ "term":{ "_id":100000100 } } }

    例2::不存在:包含两种意思:1.这条数据根本就没有这个字段,2.这条数据的字段的值为null

    查询检查一下
    test/user-feature/_search
    {
        "query":{
            "bool":{
                "must_not":{
                    "exists":{
                        "field":"phone_aes"
                    }
                }
            }
        }
    }
      
    删除
    test/user-feature/_delete_by_query
    {
        "query":{
            "bool":{
                "must_not":{
                    "exists":{
                        "field":"phone_aes"
                    }
                }
            }
        }
    }
     
    例3:存在
    删除
    test/user-feature/_delete_by_query
    {
        "query":{
            "bool":{
                "must":{
                    "exists":{
                        "field":"phone_aes"
                    }
                }
            }
        }
    }
     
    例4:等于多少则删除
    test/_doc/_delete_by_query
    {
        "query":{
            "bool":{
                "must":{
                    "term":{
                        "flowId":182
     
                    }
                }
            }
        }
    }
     

    (3)删除所有数据(只删数据,不删表结构)

    请求方式:POST,路径填入框:/索引名称/文档名称/_delete_by_query?pretty,内容输入框默认{"query":{"match_all":{}}}

    五、查询

    (1)组合查询

    test/_doc/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "flowId": 184
              }
            },
            {
              "match": {
                "requestJson": "15728898901"
              }
            }
          ]
        }
      }
    }

    (2)查询某列最大最小值

    test/_search
    {
      "_source": [
        "importedTime"
      ],
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "flowId": 258
              }
            }
          ]
        }
      },
      "aggs": {
        "max_time": {
          "max": {
            "field": "importedTime"
          }
        },
        "min_time": {
          "min": {
            "field": "importedTime"
          }
        }
      }
    }

    六、调整索引所能读取的最大数量

    请求方式:PUT,路径填入框:/索引名称/_settings,内容输入框默认{"index":{"max_result_window":1000000}}

  • 相关阅读:
    一条Sql的Spark之旅
    Redis学习笔记:Redis在C#中的使用
    MySQL_表操作
    git上传新项目到coding
    Jenkins 安装 on centos7
    day 36
    表单生成器(Form Builder)之表单数据存储结构mongodb篇
    ORA-16032和ORA-07286 LOG_ARCHIVE_DEST_1没生效
    SQL查询小案例
    mysql从5.6升级到5.7后出现 Expression #1 of ORDER BY clause is not in SELECT list,this is incompatible with DISTINCT
  • 原文地址:https://www.cnblogs.com/yulia/p/12205326.html
Copyright © 2011-2022 走看看