REST API 使用 HTTP 协议, 采用 JSON 格式
多索引查询
测试数据
POST test1/_doc{"name": "tobias1","company": 100912}POST test2/_doc{"name": "tobias2","company": 100913}POST test3/_doc{"name": "tobias3","company": 100914}
GET test*/_search/
{"took" : 1,"timed_out" : false,"_shards" : {"total" : 3,"successful" : 3,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 3,"relation" : "eq"},"max_score" : 1.0,"hits" : [{"_index" : "test1","_type" : "_doc","_id" : "MBGYKIABA0UtmzhiVsN9","_score" : 1.0,"_source" : {"name" : "tobias1","company" : 100912}},{"_index" : "test2","_type" : "_doc","_id" : "MRGYKIABA0UtmzhiVsPV","_score" : 1.0,"_source" : {"name" : "tobias2","company" : 100913}},{"_index" : "test3","_type" : "_doc","_id" : "MhGYKIABA0UtmzhiV8Ms","_score" : 1.0,"_source" : {"name" : "tobias3","company" : 100914}}]}}
-
GET xxx*/_search
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 0,"successful" : 0,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 0,"relation" : "eq"},"max_score" : 0.0,"hits" : [ ]}}
无通配符开头的数据,默认
allow_no_indices=trueGET xxx*/_search?allow_no_indices=false
{"error" : {"root_cause" : [{"type" : "index_not_found_exception","reason" : "no such index [xxx*]","resource.type" : "index_or_alias","resource.id" : "xxx*","index_uuid" : "_na_","index" : "xxx*"}],"type" : "index_not_found_exception","reason" : "no such index [xxx*]","resource.type" : "index_or_alias","resource.id" : "xxx*","index_uuid" : "_na_","index" : "xxx*"},"status" : 404}
不允许索引不存在将会响应失败
日期数学格式
测试数据
POST test-2022_04_12/_doc{"context":"hello,how are you"}POST test-2022_04_13/_doc{"context":"hello,how are you 04-13"}POST test-2022_04_14/_doc{"context":"hello,how are you 04-14"}
GET /test-2022_04_12,test-2022_04_13,test-2022_04_14/_search
- 假如今天是 2022_04_15, 如上查询与下面查询等同
```json
//GET /
/_search{ “query”: { “match_all”: {} } }
//所有特殊字符都应进行URI编码,如下查询有效
GET /%3Ctest-%7Bnow%2Fd-3d%7Byyyy_MM_dd%7D%7D%3E%2C%3Ctest-%7Bnow%2Fd-2d%7Byyyy_MM_dd%7D%7D%3E%2C%3Ctest-%7Bnow%2Fd-d%7Byyyy_MM_dd%7D%7D%3E/_search { “query”: { “match_all”: {} } }
/////////////////////////////////////////////////////////////////////////////// { “took” : 1, “timed_out” : false, “_shards” : { “total” : 3, “successful” : 3, “skipped” : 0, “failed” : 0 }, “hits” : { “total” : { “value” : 3, “relation” : “eq” }, “max_score” : 1.0, “hits” : [ { “_index” : “test-2022_04_12”, “_type” : “_doc”, “_id” : “TRGwLYABA0UtmzhicsNN”, “_score” : 1.0, “_source” : { “context” : “hello,how are you” } }, { “_index” : “test-2022_04_13”, “_type” : “_doc”, “_id” : “ThG3LYABA0UtmzhixMOO”, “_score” : 1.0, “_source” : { “context” : “hello,how are you 04-13” } }, { “_index” : “test-2022_04_14”, “_type” : “_doc”, “_id” : “TxG3LYABA0Utmzhi8sM-“, “_score” : 1.0, “_source” : { “context” : “hello,how are you 04-14” } } ] } } ```
日期数学字符百分比编码
| 字符 | URI |
|---|---|
| < | %3C |
| > | %3E |
| / | %2F |
| { | %7B |
| } | %7D |
| | | %7C |
| + | %2B |
| : | %3A |
| , | %2C |
日期数学格式解析实例
- 假如now 为 2022-04-15 下午
| 索引模式 | 解析结果 |
| —- | —- |
|
| test-2022.04.15 | | | test-2022.04.01 | | | test-2022.04 | | | test-2022.03 | | | test-2022.04.16 |
