ElasticSearch——常用查询命令

集群相关

--查询集群健康状态
GET _cluster/health

--查询所有节点
GET _cat/nodes

--查询索引及分片的分布
GET _cat/shards

--查询所有插件
GET _cat/plugins

索引相关查询

--查询所有索引及容量
GET _cat/indices

--查询索引映射结构
GET my_index/_mapping

--查询所有索引映射结构
GET _all

--查询所有的相同前缀索引
GET my-*/_search

--查询所有索引模板
GET _template

--查询具体索引模板
GET _template/my_template

索引相关操作

1、写入索引模板

PUT _template/my_template
{
    "template" : "my-*",
    "order" : 0,
    "settings" : {
        "number_of_shards" : 10,
         "number_of_replicas" : 0
    },
    "mappings": {

      "default": {

  "_all": {
        "enabled": false
      },
        "properties": {
          "name": {
            "type": "text"
          },
          "age": {
            "type": "long"
          }
        }
    }
  }
}

2、创建索引映射结构

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "name": {
          "type": "text"
        },
        "blob": {
          "type": "binary"
        }
      }
    }
  }
}

3、写入索引

PUT my_index/doc/1
{
  "name": "Some binary blob",
  "blob": "U29tZSBiaW5hcnkgYmxvYg=="
}

4、删除索引

DELETE my-index

DSL query查询

--1.查询所有
GET _search
{
  "query": {
    "match_all": {}
  }
}

--2.查询单个索引 的 固定属性
--精确匹配
GET _search
{
  "query": {
    "term": { "name" : "you" }
  }
}

--模糊匹配
GET _search
{
  "query": {
    "match": { "name" : "you" }
  }
}
--范围查找
GET _search
{
  "query": {
    "range": {
        "age":{ "gte" : 15 , "lte" : 25 }
    }
  }
}

 GET indexName/_search
 {
   "query": {
     "wildcard":{"relateId":"*672499460503*"}
   }
 }

--3.功能性查询
--过滤
GET my_index/_search
{
  "query": {
    "bool": {
      "filter": {
        "term":{"age":1095}
      }
    }
  }
}

--或 or
GET my - test / _search {
"query": {
"bool": {
"should": [{
"term": {
"name": "you"
}
}, {
"match": {
"age": 20
}
}]
}
}
}

--与 AND
GET my-test/_search
{
  "query": {
    "bool": {
      "must" : [{
        "match" : {
          "name" : "you"
        }
      },{
        "range":{
        "age":{
          "from" : 10 , "to" : 20
        }
        }
      }]
    }
  }
}

--必须 =
GET my_index/_search
{
  "query": {
    "bool": {
      "must" : {
        "range" : {
          "age" : { "from" : 10, "to" : 20 }
        }
      }
    }
  }
}

--必须不 not
GET my_index/_search
{
  "query": {
    "bool": {
      "must_not" : {
        "term" : {
          "name" : "you"
        }
      }
    }
  }
}

--复合查找
GET my_index/_search
{
"query": {
"bool": {
"should": [{
"match": {
"age": 40
}
},
{
"match": {
"age": 20
}
}],
"filter": {
  "match":{
    "name":"you"
  }
}
}
}
}

--4.索引迁移
--场景 从A索引 复制到B索引
POST _reindex
{
  "source": {
    "index": "my_index"
  },
  "dest": {
    "index": "new_my_index"
  }
}

--5.基于查询的删除
POST test-index/_delete_by_query
{
  "query":{
        "term": {
         "cameraId":"00000000002"
        }
  }

}

--查询
GET test-index/_search
{
  "query":{
        "term": {
         "cameraId":"00000000002"
        }
  }
}

可在kibana的Dev Tools控制板上执行以上命令:

参考链接:https://blog.csdn.net/ailice001/article/details/79541816

原文地址:https://www.cnblogs.com/caoweixiong/p/11792049.html

时间: 2024-07-31 16:40:51

ElasticSearch——常用查询命令的相关文章

Linux Centos6.x 下常用查询命令整理

Linux Centos6.x 下常用查询命令整理 ---- 1.系统基本信息 ---- 查看 系统版本 cat /etc/redhat-release [[email protected] ~]# cat /etc/redhat-release CentOS release 6.9 (Final) 查看 处理器架构 arch 或 uname -m [[email protected] ~]# arch x86_64 [[email protected] ~]# uname -m x86_64

elasticsearch常用查询

query DSL match 查询 { "match": { "tweet": "About Search" } } 注:match查询只能就指定某个确切字段某个确切的值进行搜索,做精确匹配搜索时, 你最好用过滤语句,因为过滤语句可以缓存数据. match_phrase 查询 { "query": { "match_phrase": { "title": "quick bro

linux系统运维常用查询命令

linu 中常用的查看系统的命令.cpu.内存.网卡流量 查看cpu信息概要(ubuntu .linux.centos):#lscpuArchitecture:????????? x86_64?????????????????????????? #架构x86_64CPU(s):??????????????? 2?????????????????????????????????? #逻辑cpu颗数是2Thread(s) per core:??? 1?????????? ? ? ? ? ? ? ?

mysql常用查询命令

1.mysql登录命令 #mysql -h 192.168.1.1 -u root -p admin123    //(root默认密码为空),远程登录连接命令 #mysql -u root -p admin123   //本地登录命令 2.mysql退出命令 >exit 3.

[Elasticsearch] 常用查询和操作总结

1. 取得某个索引中某个字段中的所有出现过的值 这种操作类似于使用SQL的SELECT UNIQUE语句.当需要获取某个字段上的所有可用值时,可以使用terms聚合查询完成: GET /index_streets/_search?search_type=count { "aggs": { "uniq_streets": { "terms": { "field": "name.raw", "size

Eucalyptus常用查询命令

euca_conf --version 查看桉树版本 euca_conf --list-clouds 查看云控器相关信息 euca_conf --list-clusters 查看集群控制器相关信息 euca_conf --list-scs 查看存储控制器相关信息 euca_conf --list-nodes查看节点控制器及相关实例信息 euca_conf --list-services  列表桉树服务的当前状态 euca-describe-availability-zones verbose 描

【原创】大数据基础之Mongodb(2)常用查询命令

1 下载 https://www.mongodb.com/download-center/community 比如: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgz 2 连接 # cd $MONGODB_HOME# bin/mongo master:27017/database_name 3 查询 1 count >db.getCollection('table_name').find({}).count() 2 g

cdb与pdb的一些常用查询命令

[[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Sat Mar 5 19:57:04 2016 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Produ

ElasticSearch 常用的查询过滤语句

query 和  filter 的区别请看: http://www.cnblogs.com/ghj1976/p/5292740.html    Filter DSL   term 过滤 term主要用于精确匹配哪些值,比如数字,日期,布尔值或 not_analyzed 的字符串(未经分析的文本数据类型): { "term": { "age":    26           }} { "term": { "date":   &