2017-09-24 64 views
1

我對ES這個簡單的數據::如何在elasticsearch上使用「REST請求URI」做一個範圍過濾器?

curl -XPUT localhost:9200/dt/art/1 -d '{ "age": 77 }' 
curl -XPUT localhost:9200/dt/art/2 -d '{ "age": 19 }' 
curl -XPUT localhost:9200/dt/art/3 -d '{ "age": 42 }' 
curl -XPUT localhost:9200/dt/art/4 -d '{ "age": 33 }' 

是否有可能做一個範圍過濾器上的「年齡」使用「REST request URI」?

現在,我只能用 「REST request body」 得到這樣的:

$ curl "localhost:9200/dt/art/_search?pretty" -d'{ 
    "query": { 
     "bool": { "must": { "match_all": {} }, 
       "filter": { 
        "range": { 
        "age": { "gte": 20, "lte": 50}}}}}}' 


{ "took" : 8, "timed_out" : false, 
    "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, 
    "hits" : { 
    "total" : 2, 
    "max_score" : 1.0, 
    "hits" : [ 
     { "_index" : "dt", "_type" : "art", "_id" : "4", "_score" : 1.0, 
     "_source" : { "age" : 33 } }, 
     { "_index" : "dt", "_type" : "art", "_id" : "3", "_score" : 1.0, 
     "_source" : { "age" : 42 } } 
    ] 
    } 
} 
$ 

回答

3

是。

GET dt/art/_search?q=age:[19+TO+50] 

對於約會,你可以使用這樣的事情

_search?q=metrictype:os+datetime:[\"2016-08-30 10:00:00\"+to+\"2016-08-30 10:30:00\" ]+fields:datetime,cpu,disk" 
相關問題