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:[2012-01-01 TO 2012-12-31]---All days in 2012 count:[10 TO *]---Numbers from 10 upwards count:>=10---Numbers from 10 upwards
3、總覽
curl localhost:9200/_cat/nodes?v //查看node狀態 curl localhost:9200/_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:19200/_cat/nodes?v ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 192.168.243.74 50 98 0 0.09 0.08 0.10 di - node5 192.168.243.35 39 90 0 0.11 0.19 0.23 mdi - node2 192.168.243.11 57 99 1 0.19 0.14 0.14 mdi * node1 192.168.243.51 65 95 0 0.07 0.09 0.13 di - node4 192.168.243.40 50 95 0 0.05 0.14 0.20 mdi - node3
4.2、查詢節點健康狀態
[zhang@node2 ~]$ curl localhost:19200/_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 1561104338 16:05:38 zhang green 5 5 3074 157326 0 0 0 0 - 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 615 1.9tb 9.2tb 8.9tb 18.2tb 51 192.168.243.11 192.168.243.11 node1 615 2.3tb 8.7tb 9.4tb 18.2tb 47 192.168.243.35 192.168.243.35 node2 614 2.2tb 7.6tb 10.5tb 18.2tb 42 192.168.243.40 192.168.243.40 node3 615 2.2tb 7.5tb 10.6tb 18.2tb 41 192.168.243.51 192.168.243.51 node4 615 2.1tb 7.1tb 11tb 18.2tb 39 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.10 ggf3VQMbRXmhzIunDDQ1Ow 2 1 54384 0 24.3gb 12.1gb close bin_power_idx-2018.12.29 u4RfroS4QlGT49bFlFRqJg green open meter_status_idx-2012.10.01 y6pqRWC3TmaAT5ZNfXOxSw 2 1 33335 0 18.7mb 9.3mb green open power_json-7326403-2019.04 EZGhuUBUSA28nspkFL_ibQ 2 1 59416810 0 31.5gb 15.7gb green open power_json-7326406-2019.02 hVow4ibaRAS2kQtLXPbCJQ 2 1 115093304 0 58.3gb 29.1gb green open power_json-7326419-2019.06 uZfizhIHS361y9-u5FvgAw 2 1 97416 0 42mb 20.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-7326403-2019.04 EZGhuUBUSA28nspkFL_ibQ 2 1 59416810 0 31.5gb 15.7gb green open power_json-7326406-2019.02 hVow4ibaRAS2kQtLXPbCJQ 2 1 115093304 0 58.3gb 29.1gb green open power_json-7326419-2019.06 uZfizhIHS361y9-u5FvgAw 2 1 97416 0 42mb 20.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" : 256, "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" : 256, "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" : 256 }, "CT" : { "type" : "float" }, "GLYS" : { "type" : "float" //浮點型 }, "HNAME" : { "type" : "keyword", "ignore_above" : 256 }, "HOUSE" : { "type" : "keyword", "ignore_above" : 256 }, "IB" : { "type" : "float" }, "ID" : { "type" : "keyword", "ignore_above" : 256 }, "IMAX" : { "type" : "float" }, "TESTID" : { "type" : "keyword", "ignore_above" : 256 }, "MULT" : { "type" : "float" }, "NAME" : { "type" : "keyword", "ignore_above" : 256 }, "ORG_NO" : { "type" : "keyword", "ignore_above" : 256 }, "O_N_5" : { "type" : "keyword", "ignore_above" : 256 }, "PROVINCE" : { "type" : "keyword", "ignore_above" : 256 }, "PT" : { "type" : "float" }, "RAP_R" : { "type" : "float" }, "SOLAR" : { "type" : "long" }, "TG_ADDR" : { "type" : "keyword", "ignore_above" : 256 }, "TIME" : { "type" : "date" }, "UNIT" : { "type" : "keyword", "ignore_above" : 256 }, "VAL" : { "type" : "float" }, "file" : { "type" : "keyword", "ignore_above" : 256 } } } }, "settings" : { "index" : { "refresh_interval" : "5s", "number_of_shards" : "2", "provided_name" : "power_json-7326414-2019.01", "merge" : { "scheduler" : { "max_thread_count" : "1" } }, "creation_date" : "1546841799515", "number_of_replicas" : "1", "uuid" : "40WyopBKRji-tfz4gLREHQ", "version" : { "created" : "5060099" } } } }, "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" : 13625, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1024729047326, "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" : 0,"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" : 0,"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" : 0,"VAL" : 14145.36, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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" : 3584, //花費時間 "timed_out" : false, //是否超時 "_shards" : { //分片的詳細信息 "total" : 416, //查詢的分片數 "successful" : 416, //查詢成功的分片,不代表分片上有我們需要的信息,只是代表對分片查詢成功了 "skipped" : 0, "failed" : 0 }, "hits" : { //命中的情況 "total" : 442, //查詢到的結果 "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" : 0, "TESTID" : "10000000107326732674", "VAL" : 2287.85, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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" : 49, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 442, "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" : 0,"VAL" : 2287.85, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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" : 0,"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" : 0,"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" : 3435, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 442, "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" : 0,"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" : 0,"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" : 0,"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" : 526, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 442, "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" : 0,"CT" : 1.0, "PT" : 1.0, "RAP_R" : 0.0, "GLYS" : 0.0,"file" : "7326414_2019_06_20.csv" }, "sort" : [ 1560355200000 ] }, { "_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" : 0,"CT" : 1.0, "PT" : 1.0, "RAP_R" : 0.0, "GLYS" : 0.0,"file" : "7326414_2019_06_19.csv" }, "sort" : [ 1560268800000 ] }, ] } }
4.11、模糊查詢
[zhang@node2 ~]$ curl 'localhost:19200/power_json*/_search?pretty&analyze_wildcard&q=TESTID:10000000107326732674' //模糊查詢 { "took" : 38, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 442, "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" : 0,"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" : 12636, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1811138155, "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" : 1,"VAL" : 0.0, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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" : 2933, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1024729047326, "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" : 2894, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1024729047326, "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" : 4078, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 5732636, "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" : 1,"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: (3) [globbing] error: bad range specification after pos 52 #要加 -g [zhang@node2 ~]$ curl -g 'localhost:19200/power_json*/_search?pretty&q=TIME:[2019-06-19%20TO%202019-06-20]' //index的日期不對,沒有日 { "took" : 39, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } } [zhang@node2 ~]$ curl 'localhost:19200/_cat/indices/power_json*2019.06*' green open power_json-7326403-2019.06 Jso0F_IaS5O-jtA5a8Cgjg 2 1 21975591 0 12.4gb 6.2gb green open power_json-7326402-2019.06 u4awVtFcQQSL3HBwULFIDg 2 1 54000760 0 29.8gb 14.9gb green open power_json-7326407-2019.06 tv2L2iZ3RVS_jhZHKhbVtg 2 1 40077389 0 22.5gb 11.2gb green open power_json-7326416-2019.06 eLBfBfH1RnK_3HWSYzo8Nw 2 1 16890423 0 8.9gb 4.4gb green open power_json-7326404-2019.06 3N8Yc0fuT8SiygGdjmV_AA 2 1 20415087 0 11.2gb 5.5gb green open power_json-7326419-2019.06 uZfizhIHS361y9-u5FvgAw 2 1 97416 0 42mb 20.9mb green open power_json-7326413-2019.06 QgwuyjdoR-qN_CUSU1SOCw 2 1 62795546 0 36.1gb 18.2gb green open power_json-7326405-2019.06 GpFkpiffTZusRij4kf8lMg 2 1 8635077 0 4.7gb 2.3gb green open power_json-7326417-2019.06 XqoJssMOQz2h2mcnXA5dsA 2 1 43434776 0 23.3gb 11.6gb green open power_json-7326410-2019.06 M-osUUC2QIO2zTzGRV4JOQ 2 1 17899431 0 9.7gb 4.8gb green open power_json-7326409-2019.06 fuY0AQuxQfKG9upBovKBIA 2 1 27089634 0 15.1gb 7.5gb green open power_json-7326414-2019.06 Li-MASxIQAOcq4AUDfZuvA 2 1 2957773262 0 16.3gb 8.2gb green open power_json-7326406-2019.06 YlmVgU4rS8WqcTOX49DbFg 2 1 7326500276 0 20.6gb 10.1gb green open power_json-7326401-2019.06 xPJVFHV4Q3Ku5ivblpELnw 2 1 28431876 0 15.6gb 7.8gb green open power_json-7326412-2019.06 cxhzsJWKTymC2jFPko90NQ 2 1 6851020 0 3.9gb 1.9gb green open power_json-7326415-2019.06 2u0BLAeEQcehmrTyfkfI6A 2 1 27869666 0 15gb 7.5gb green open power_json-7326408-2019.06 6z6YBG2PT3KQzRd75hq0cA 2 1 39191130 0 20.8gb 10.4gb green open power_json-7326411-2019.06 9T6Zf2wlRj-d-kMx_YuOSw 2 1 15324628 0 8.4gb 4.2gb [zhang@node2 ~]$ curl -g 'localhost:19200/power_json*/_search?pretty&q=TIME:[2019-05%20TO%202019-06]' { "took" : 1642, "timed_out" : false, "_shards" : { "total" : 416, "successful" : 416, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1386487997, "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" : 0,"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" : 0,"VAL" : 6632.25, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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" : 0,"VAL" : 19618.12, "MULT" : 1.0, "IB" : 5.0, "IMAX" : 60.0, "SOLAR" : 0,"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:19200/power_json-7326411-2019.06/_close
[zhang@node2 ~]$ curl -XPOST localhost:19200/power_json-7326411-2019.06/_open
4.18、刪除符合條件的記錄
curl -XPOST 'localhost:19200/power_json*/_delete_by_query?pretty&q=TESTID:781128