Elasticsearch-URL查询实例解析
ES(elasticsearch),以下简称ES
ES的查询有query、URL两种方式,而URL是比较简洁的一种,本文主要以实例探讨和总结URL的查询方式
1、语法
curl [ -s][ -g][ -X<REST Verb>][ -H 'Content-Type: application/json'] '<Node>:<Port>/<Index>[/Type][/ID]/_search?pretty&q=<search string>'
注意要用''包起来,否则后面的&会被识别为“后台执行”,即&后面的内容被忽略
-s 不输出查询的时间那些东西
-g 做转义用
<REST Verb>:REST风格的语法谓词,GET/POST/PUT
<Node>:节点ip,默认使用localhost
<port>:节点端口号,默认80,ES默认使用9200
<Index>:索引名,支持通配符,power_json*
<Type>:索引类型,由于一个index只有一个type,可不输入
<ID>:操作对象的ID号,可不输入
q :前面加&,后跟查询语句
2、常用参数
q---查询字符串
sort---排序执行。可以是fieldName或 fieldName:asc/ 的形式fieldName:desc。fieldName可以是文档中的实际字段,也可以是特殊_score名称,表示基于分数的排序。可以有几个sort参数(顺序很重要)。
from---从命中的索引开始返回。默认为0。
size---要返回的点击次数。默认为10。
_source_include---查询包含某些source字段的文档。
_source_exclude---查询不包含某些source字段的文档。
timeout---搜索超时,将搜索请求限制在指定的时间值内执行,并使用在到期时累积的点击数进行保释。默认为无超时。
default_field---默认为index.query.default_field,即未指定字段前缀时返回所有字段,索引设置为*
default_operator---默认查询运算符,未指定时默认为OR。
analyzer---用于分析查询字符串的分析器名称。
_source---设置为false禁用_source字段检索。
analyze_wildcard---是否应分析通配符和前缀查询,默认为false
status:active---where the status field contains active
---(status相当于fieldname,active相当于值----->TESTID:39232032303039,由于=被用在了前面“q=”,所以这里用“:”代替了“=”)
title:(quick OR brown)---where the title field contains quick or brown. If you omit the OR operator the default operator will be used
author:"John Smith"---where the author field contains the exact phrase "john smith"
_exists_:title---where the field title has any non-null value
date:[-- TO --]---All days in
count:[ TO *]---Numbers from upwards
count:>=---Numbers from upwards
3、总览
curl localhost:/_cat/nodes?v //查看node状态
curl localhost:/_cat/health?v //查看集群健康状况curl 'localhost:9200/_cat/indices?v&s=index' //s=sort排序
curl 'localhost:9200/_cat/indices/power_json*?v&s=index' //只查power_json
curl 'localhost:9200/_cat/allocation?v&s=node' //获取集群的节点列表
curl 'localhost:9200/power_json*?pretty' //pretty,美观
curl 'localhost:9200/power_json*/_search?pretty&q=_exists_:MULT' //是否存在
curl 'localhost:9200/power_json*/_search?pretty&q=TESTID:10000000107326732674' //查指定的字段值
curl 'localhost:9200/power_json*/_search?pretty&q=TESTID:10000000107326732674&size=3' //查指定的字段值,并只显示3个
curl 'localhost:9200/power_json*/_search?pretty&q=TESTID:10000000107326732674&from=2&size=3' //从第3个开始只显示3个,即3/4/5
curl 'localhost:9200/power_json*/_search?pretty&q=TESTID:10000000107326732674&sort=TIME:desc' //按时间排序,desc降序,默认为升序
curl 'localhost:9200/power_json*/_search?pretty&analyze_wildcard&q=TESTID:10000000107326732674' //模糊查询
curl 'localhost:9200/power_json*/_search?pretty&q=VAL:<200' //比较大小
curl 'localhost:9200/power_json*/_search?pretty&_source=false' //是否显示
curl 'localhost:9200/power_json*/_search?pretty&_source_includes=TIME,VAL' //设置包含的字段
curl -g 'localhost:9200/power_json*/_search?pretty&q=(SOLAR:1%20AND%20CENTRAL:1)' //组合查询
curl -g 'localhost:9200/power_json*/_search?pretty&q=TIME:[2019-05%20TO%202019-06]' //范围查询
4、详解
4.1、查询节点
heap.percent:堆内存,1/2最大内存-1和31之间取较小的值,高的话就是ES集群负担比较重,解决:关闭一些索引(阈值差不多可以定在80左右)后会释放一部分heap.percent,但不会释放disk.percent
ram.percent:一直挺高,物理内存的使用情况,Lucene会将闲置的内存都占用做cache,如果有应用使用内存时,cache会被释放出来
cpu:一般不会很高,5以下吧,如果有很多query的话会高,如果一直高释放不掉可能查询语句有问题
node.role:【mdi】master data i查询接口(可否在节点上查询)
[zhang@node2 ~]$ curl localhost:/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.243.74 0.09 0.08 0.10 di - node5
192.168.243.35 0.11 0.19 0.23 mdi - node2
192.168.243.11 0.19 0.14 0.14 mdi * node1
192.168.243.51 0.07 0.09 0.13 di - node4
192.168.243.40 0.05 0.14 0.20 mdi - node3
4.2、查询节点健康状态
[zhang@node2 ~]$ curl localhost:/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
:: zhang green - 100.0%
4.3、查询节点
disk.percent显示占用的硬盘空间
[zhang@node2 ~]$ curl 'localhost:19200/_cat/allocation?v&s=node'
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
.9tb .2tb .9tb .2tb 192.168.243.11 192.168.243.11 node1
.3tb .7tb .4tb .2tb 192.168.243.35 192.168.243.35 node2
.2tb .6tb .5tb .2tb 192.168.243.40 192.168.243.40 node3
.2tb .5tb .6tb .2tb 192.168.243.51 192.168.243.51 node4
.1tb .1tb 11tb .2tb 192.168.243.74 192.168.243.74 node5
4.4、查询索引
有很多,本文只摘取了一部分。
[zhang@node2 ~]$ curl 'localhost:19200/_cat/indices?v&s=index' //查看索引,并以索引名字排序(s=sort)
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open bin_power_idx-2000.07. ggf3VQMbRXmhzIunDDQ1Ow .3gb .1gb
close bin_power_idx-2018.12. u4RfroS4QlGT49bFlFRqJg
green open meter_status_idx-2012.10. y6pqRWC3TmaAT5ZNfXOxSw .7mb .3mb
green open power_json--2019.04 EZGhuUBUSA28nspkFL_ibQ .5gb .7gb
green open power_json--2019.02 hVow4ibaRAS2kQtLXPbCJQ .3gb .1gb
green open power_json--2019.06 uZfizhIHS361y9-u5FvgAw 42mb .9mb [zhang@node2 ~]$ curl 'localhost:19200/_cat/indices/power_json*?v&s=index' //只查看power_json索引,并以索引名字排序(s=sort)
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open power_json--2019.04 EZGhuUBUSA28nspkFL_ibQ .5gb .7gb
green open power_json--2019.02 hVow4ibaRAS2kQtLXPbCJQ .3gb .1gb
green open power_json--2019.06 uZfizhIHS361y9-u5FvgAw 42mb .9mb
4.5、查询索引的具体记录信息
[zhang@node2 ~]$ curl 'localhost:19200/power_json*?pretty'
{
"power_json-7326414-2019.01" : {
"aliases" : { },
"mappings" : {
"_default_" : {
"dynamic_templates" : [
{
"string_fields" : {
"match" : "*",
"unmatch" : "BIN*",
"match_mapping_type" : "string",
"mapping" : {
"ignore_above" : ,
"type" : "keyword"
}
}
},
{
"date_fields" : {
"match" : "TIME",
"mapping" : {
"type" : "date"
}
}
},
{
"bin_fields" : {
"match" : "BIN*",
"mapping" : {
"type" : "binary"
}
}
}
]
},
"power_json" : {
"dynamic_templates" : [
{
"string_fields" : {
"match" : "*",
"unmatch" : "BIN*",
"match_mapping_type" : "string",
"mapping" : {
"ignore_above" : ,
"type" : "keyword" //字符串类型
}
}
},
{
"date_fields" : {
"match" : "TIME",
"mapping" : {
"type" : "date"
}
}
},
{
"bin_fields" : {
"match" : "BIN*",
"mapping" : {
"type" : "binary"
}
}
}
],
"properties" : {
"CENTRAL" : {
"type" : "long"
},
"CITY" : {
"type" : "keyword",
"ignore_above" :
},
"CT" : {
"type" : "float"
},
"GLYS" : {
"type" : "float" //浮点型
},
"HNAME" : {
"type" : "keyword",
"ignore_above" :
},
"HOUSE" : {
"type" : "keyword",
"ignore_above" :
},
"IB" : {
"type" : "float"
},
"ID" : {
"type" : "keyword",
"ignore_above" :
},
"IMAX" : {
"type" : "float"
},
"TESTID" : {
"type" : "keyword",
"ignore_above" :
},
"MULT" : {
"type" : "float"
},
"NAME" : {
"type" : "keyword",
"ignore_above" :
},
"ORG_NO" : {
"type" : "keyword",
"ignore_above" :
},
"O_N_5" : {
"type" : "keyword",
"ignore_above" :
},
"PROVINCE" : {
"type" : "keyword",
"ignore_above" :
},
"PT" : {
"type" : "float"
},
"RAP_R" : {
"type" : "float"
},
"SOLAR" : {
"type" : "long"
},
"TG_ADDR" : {
"type" : "keyword",
"ignore_above" :
},
"TIME" : {
"type" : "date"
},
"UNIT" : {
"type" : "keyword",
"ignore_above" :
},
"VAL" : {
"type" : "float"
},
"file" : {
"type" : "keyword",
"ignore_above" :
}
}
}
},
"settings" : {
"index" : {
"refresh_interval" : "5s",
"number_of_shards" : "",
"provided_name" : "power_json-7326414-2019.01",
"merge" : {
"scheduler" : {
"max_thread_count" : ""
}
},
"creation_date" : "",
"number_of_replicas" : "",
"uuid" : "40WyopBKRji-tfz4gLREHQ",
"version" : {
"created" : ""
}
}
}
},
"power_json-7326410-2019.01" : {
"aliases" : { },
"mappings" : {
"_default_" : {
"dynamic_templates"
........
4.6、查询字段是否存在
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=_exists_:MULT' //查MULT是否存在(_exists_)
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLLxKIIEhMjPv28Q",
"_score" : 1.0,
"_source" : {
"TIME" : "2018-07-22T16:00:00","VAL" : 773260.69,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2018_07_23.csv"
}
},
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLJXKIIEhMjPv0Rd",
"_score" : 1.0,
"_source" : {
"TIME" : "2018-07-28T16:00:00","VAL" : 12309.11,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2018_07_29.csv"
}
},
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLLxKIIEhMjPv28R",
"_score" : 1.0,
"_source" : {
"TIME" : "2018-07-22T16:00:00","HNAME" : "",
"CENTRAL" : ,"VAL" : 14145.36,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,"file" : "7326401_2018_07_23.csv"
}
},
.................
]
}
}
4.7、查询指定值的字段是否存在
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=TESTID:10000000107326732674' 查指定TESTID是否存在,status:active
{
"took" : , //花费时间
"timed_out" : false, //是否超时
"_shards" : { //分片的详细信息
"total" : , //查询的分片数
"successful" : , //查询成功的分片,不代表分片上有我们需要的信息,只是代表对分片查询成功了
"skipped" : ,
"failed" :
},
"hits" : { //命中的情况
"total" : , //查询到的结果
"max_score" : 15.078416, //打分
"hits" : [ //数组类型,把命中的详细记录及信息都列出来,hits如果不指定size,默认为10个
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWl1vKjnZsBwX43irtmd",
"_score" : 15.078416, //分数高的排在前面,
"_source" : { //记录的信息内容,_source是一个key,顺序是根据表结构来的
"TIME" : "2019-03-04T16:00:00","PROVINCE" : "TEST","HNAME" : "",
"CENTRAL" : ,
"TESTID" : "",
"VAL" : 2287.85,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_12.csv"
}
},
...........
]
}
}
4.8、查询并控制返回的记录条数
默认是10,范围为0-10000
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=TESTID:10000000107326732674&size=3' //查询3个,即1-3
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 15.078416,
"hits" : [
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWl1vKjnZsBwX43irtmd",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-04T16:00:00","HNAME" : "",
"CENTRAL" : ,"VAL" : 2287.85,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_12.csv"
}
},
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWl28lV1ZsBwX43ibsg_",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-05T16:00:00","VAL" : 2289.95,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_13.csv"
}
},
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWmbEBHSZsBwX43iFQFE",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-12T16:00:00","VAL" : 2303.92,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_20.csv"
}
}
]
}
}
4.9、查询并指定起始位置
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=TESTID:10000000107326732674&from=2&size=3' //from默认为0,从第3个开始查询3个,
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 15.078416,
"hits" : [
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWmbEBHSZsBwX43iFQFE",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-12T16:00:00","VAL" : 2303.92,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_20.csv"
}
},
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWmgl0SLZsBwX43iu1q1",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-13T16:00:00","VAL" : 2305.81,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_21.csv"
}
},
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWnjNmBzZsBwX43iwfvd",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-26T16:00:00","VAL" : 2325.95,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_04_03.csv"
}
}
]
}
}
4.10、查询并按指定字段排序
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=TESTID:10000000107326732674&sort=TIME:desc' //根据TIME排序(sort),desc降序,默认是升序
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : null,
"hits" : [
{
"_index" : "power_json-7326414-2019.06",
"_type" : "power_json",
"_id" : "AWt1FAobp__ZtGsu1rDf",
"_score" : null,
"_source" : {
"TIME" : "2019-06-12T16:00:00","VAL" : 2469.8,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_06_20.csv"
},
"sort" : [ ]
},
{
"_index" : "power_json-7326414-2019.06",
"_type" : "power_json",
"_id" : "AWtvtXvfp__ZtGsu1SUE",
"_score" : null,
"_source" : {"VAL" : 2468.26,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_06_19.csv"
},
"sort" : [ ]
},
]
}
}
4.11、模糊查询
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&analyze_wildcard&q=TESTID:10000000107326732674' //模糊查询
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 15.078416,
"hits" : [
{
"_index" : "power_json-7326414-2019.03",
"_type" : "power_json",
"_id" : "AWl1vKjnZsBwX43irtmd",
"_score" : 15.078416,
"_source" : {
"TIME" : "2019-03-04T16:00:00","VAL" : 2287.85,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326414_2019_03_12.csv"
}
},
...........
]
}
}
4.12、比较大小查询
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=VAL:<200' //对于数值型和浮点型可以用比较来查
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLLxKIIEhMjPv280",
"_score" : 1.0,
"_source" : {
"TIME" : "2018-07-22T16:00:00","HNAME" : "",
"CENTRAL" : ,"VAL" : 0.0,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2018_07_23.csv"
}
},
...........
]
}
}
4.13、查询并不显示具体内容
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&_source=false' //只要total,不要详细内容信息。
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLLxKIIEhMjPv28Q",
"_score" : 1.0
},
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLJXKIIEhMjPv0Rd",
"_score" : 1.0
},
..............
]
}
}
4.14、包含指定字段
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&_source_includes=TIME,VAL' //包含TIME和VAL字段的
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLLxKIIEhMjPv28Q",
"_score" : 1.0,
"_source" : {
"VAL" : 773260.69,
"TIME" : "2018-07-22T16:00:00"
}
},
{
"_index" : "power_json-7326401-2018.07",
"_type" : "power_json",
"_id" : "AWfbqLJXKIIEhMjPv0Rd",
"_score" : 1.0,
"_source" : {
"VAL" : 12309.11,
"TIME" : "2018-07-28T16:00:00"
}
},
..............
]
}
}
4.15、组合查询
[zhang@node2 ~]$ curl -g 'localhost:19200/power_json*/_search?pretty&q=(SOLAR:1%20AND%20CENTRAL:1)' //组合查询,
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 2.0,
"hits" : [
{
"_index" : "power_json-7326401-2018.12",
"_type" : "power_json",
"_id" : "AWf4wx0mKIIEhMjP8l5Y",
"_score" : 2.0,
"_source" : {
"TIME" : "2018-12-21T16:00:00","VAL" : 0.0,
"MULT" : 800.0,
"IB" : 1.5,
"IMAX" : 6.0,
"SOLAR" : ,"CT" : 8.0,
"PT" : 100.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2018_12_22.csv"
}
},
..........
]
}
}
4.16、范围查询
错误示例:
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&q=TIME:[2019-06-19%20TO%202019-06-20]' //范围查询 TO
curl: () [globbing] error: bad range specification after pos #要加 -g
[zhang@node2 ~]$ curl -g 'localhost:19200/power_json*/_search?pretty&q=TIME:[2019-06-19%20TO%202019-06-20]' //index的日期不对,没有日
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : null,
"hits" : [ ]
}
} [zhang@node2 ~]$ curl 'localhost:19200/_cat/indices/power_json*2019.06*'
green open power_json--2019.06 Jso0F_IaS5O-jtA5a8Cgjg .4gb .2gb
green open power_json--2019.06 u4awVtFcQQSL3HBwULFIDg .8gb .9gb
green open power_json--2019.06 tv2L2iZ3RVS_jhZHKhbVtg .5gb .2gb
green open power_json--2019.06 eLBfBfH1RnK_3HWSYzo8Nw .9gb .4gb
green open power_json--2019.06 3N8Yc0fuT8SiygGdjmV_AA .2gb .5gb
green open power_json--2019.06 uZfizhIHS361y9-u5FvgAw 42mb .9mb
green open power_json--2019.06 QgwuyjdoR-qN_CUSU1SOCw .1gb .2gb
green open power_json--2019.06 GpFkpiffTZusRij4kf8lMg .7gb .3gb
green open power_json--2019.06 XqoJssMOQz2h2mcnXA5dsA .3gb .6gb
green open power_json--2019.06 M-osUUC2QIO2zTzGRV4JOQ .7gb .8gb
green open power_json--2019.06 fuY0AQuxQfKG9upBovKBIA .1gb .5gb
green open power_json--2019.06 Li-MASxIQAOcq4AUDfZuvA .3gb .2gb
green open power_json--2019.06 YlmVgU4rS8WqcTOX49DbFg .6gb .1gb
green open power_json--2019.06 xPJVFHV4Q3Ku5ivblpELnw .6gb .8gb
green open power_json--2019.06 cxhzsJWKTymC2jFPko90NQ .9gb .9gb
green open power_json--2019.06 2u0BLAeEQcehmrTyfkfI6A 15gb .5gb
green open power_json--2019.06 6z6YBG2PT3KQzRd75hq0cA .8gb .4gb
green open power_json--2019.06 9T6Zf2wlRj-d-kMx_YuOSw .4gb .2gb [zhang@node2 ~]$ curl -g 'localhost:19200/power_json*/_search?pretty&q=TIME:[2019-05%20TO%202019-06]'
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "power_json-7326401-2019.05",
"_type" : "power_json",
"_id" : "AWrX1wkJiFDOCQ5wd2jl",
"_score" : 1.0,
"_source" : {
"TIME" : "2019-05-04T16:00:00","VAL" : 19209.93,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2019_05_12.csv"
}
},
{
"_index" : "power_json-7326401-2019.05",
"_type" : "power_json",
"_id" : "AWrX1wkJiFDOCQ5wd2jm",
"_score" : 1.0,
"_source" : {
"TIME" : "2019-05-04T16:00:00","HNAME" : "",
"CENTRAL" : ,"VAL" : 6632.25,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2019_05_12.csv"
}
},
{
"_index" : "power_json-7326401-2019.05",
"_type" : "power_json",
"_id" : "AWrX1wkJiFDOCQ5wd2jn",
"_score" : 1.0,
"_source" : {
"TIME" : "2019-05-04T16:00:00","HNAME" : "",
"CENTRAL" : ,"VAL" : 19618.12,
"MULT" : 1.0,
"IB" : 5.0,
"IMAX" : 60.0,
"SOLAR" : ,"CT" : 1.0,
"PT" : 1.0,
"RAP_R" : 0.0,
"GLYS" : 0.0,"file" : "7326401_2019_05_12.csv"
}
},
.............
]
}
}
4.17、关闭和打开索引
[zhang@node2 ~]$ curl -XPOST localhost:/power_json--2019.06/_close
[zhang@node2 ~]$ curl -XPOST localhost:/power_json--2019.06/_open
4.18、删除符合条件的记录
curl -XPOST 'localhost:19200/power_json*/_delete_by_query?pretty&q=TESTID:
Elasticsearch-URL查询实例解析的更多相关文章
- gin的url查询参数解析
gin作为go语言最知名的网络库,在这里我简要介绍一下url的查询参数解析.主要是这里面存在一些需要注意的地方.这里,直接给出代码,和运行结果,在必要的地方进行分析. 代码1: type Struct ...
- url查询参数解析
url查询参数解析 1.获取url的各部分值 举例http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 UR ...
- Node基础:url查询参数解析之querystring
模块概述 在nodejs中,提供了querystring这个模块,用来做url查询参数的解析,使用非常简单. 模块总共有四个方法,绝大部分时,我们只会用到 .parse(). .stringify() ...
- Elasticsearch学习系列之term和match查询实例
Elasticsearch查询模式 一种是像传递URL参数一样去传递查询语句,被称为简单查询 GET /library/books/_search //查询index为library,type为boo ...
- querystring 解析url 查询字符串
对前端同学来说,经常要碰到一种比较麻烦的情况,那就是url查询字符串的解析问题.说起来也不难,就是比较麻烦. 具体来处理这种情况的时候,相信有一部分同学就是针对具体项目中的需要的字符去正则匹配一下,业 ...
- 添加jQuery方法解析url查询部分
Web前端不同页面间传值可以使用 cookies.localStorage 和 sessionStorage 等本地存储. 但是,今天我们尝试使用 url 查询,假设我们要传递字符串 str 到 mo ...
- 黑马旅游网 解析url查询字符串
function getUrlParam(name) { let reg = new RegExp("(^|&)" + name + "=([^&]*)( ...
- day53:django:URL别名/反向解析&URL分发&命名空间&ORM多表操作修改/查询
目录 1.URL别名&反向解析 2.URL分发&命名空间 3.ORM多表操作-修改 4.ORM多表操作-查询 4.1 基于对象的跨表查询 4.2 基于双下划线的跨表查询 4.3 聚合查 ...
- Datatables插件1.10.15版本服务器处理模式ajax获取分页数据实例解析
一.问题描述 前端需要使用表格来展示数据,找了一些插件,最后确定使用dataTables组件来做. 后端的分页接口已经写好了,不能修改.接口需要传入页码(pageNumber)和页面显示数据条数(pa ...
随机推荐
- Object arrays cannot be loaded when allow_pickle=False
问题再现 代码是Deep Learning with Python中的: from keras.datasets import imdb (train_data, train_labels), (te ...
- JavaEE--使用百度echarts实现地图报表
参考:http://echarts.baidu.com/option.html#title https://www.cnblogs.com/zhangyong123/p/4974554.html ht ...
- @Data与@ConfigurationProperties 简化配置属性数据
参考地址:https://www.cnblogs.com/FraserYu/p/11261916.html 在编写项目代码时,我们要求更灵活的配置,更好的模块化整合.在 Spring Boot 项 ...
- 提示Asp.net4.5未在web服务器上注册
在用vs2012代开项目时, 每回都显示Asp.net4.5未在web服务器上注册,最后是由于没有下载一个补丁的原因,只需要下载安装补丁 VS11-KB3002339.exe ,下载地址:https: ...
- linux配置词典goldendict
在mint 18下使用通过, ubuntu 类似. 方法: 通过软件中心安装goldendict,或者 sudo apt install goldendict 通过网页抓取程序, 见附录 下载朗道词典 ...
- RepeatSubmitInterceptor extends HandlerInterceptorAdapter
package com.ruoyi.framework.interceptor; import java.lang.reflect.Method; import javax.servlet.http. ...
- 常见的nosql数据库有哪些?以及他们的特点与区别?
一.常见的nosql 二.Redis,Memcache,MongoDb的特点 (1).Redis 优点: 1.支持多种数据结构,如 string(字符串). list(双向链表).dict(hash表 ...
- ZJNU 1067 - 约瑟夫——中级
打表处理(否则Case 1超时) 对m进行枚举,每次枚举进行一次判断 因为好人坏人均为k个,那么只要让下一个死亡的人的位置p保证在1~剩余坏人数量之间即可,不满足则直接break枚举下一个m 实际上对 ...
- Spring--Spring 注入
Spring 提供了三种主要的装配机制: 在 XML 中进行显式配置 在 Java 中进行显式配置 隐式的 bean 发现机制和自动装配 Spring 从两个角度来实现自动化装配: 组件扫描:Spri ...
- nodejs服务后台持续运行三种方法
一.利用 forever forever是一个nodejs守护进程,完全由命令行操控.forever会监控nodejs服务,并在服务挂掉后进行重启. 1.安装 forever npm install ...