i have a sentence to query a group of users by terms (keyword field present uid
) and with a range limit (long filed present unixtime ),the sentence can be executed in Kibana and curl, but when I use golang client(https://github.com/olivere/elastic) to perform the query, after json. Unmarshal(), the sentence is tampered,the range request is abandoned, why? my sentence disobey the json's rule?
package main
import (
"encoding/json"
"fmt"
)
var hot_cache map[string]byte
var followers []string
var prefix = "{\"constant_score\" : {\"filter\" : {\"bool\" : {\"filter\" : {\"range\" : {\"unixtime\" : {\"gte\" : %d, \"lte\" : %d}}}, \"filter\" : {\"terms\" : {\"uid\" : ["
var suffix = "]}}}}}}"
func main() {
tmp := prefix
tmp += "\""
tmp += "123"
tmp += "\""
tmp += suffix
qstr := fmt.Sprintf(tmp, 1, 2)
fmt.Println("raw: ", qstr)
var f interface{}
err := json.Unmarshal([]byte(qstr), &f)
if err != nil {
panic(err)
}
fmt.Println("json: ", f)
}
Output:
raw: {"constant_score" : {"filter" : {"bool" : {"filter" : {"range" : {"unixtimestamp" : {"gte" : 1, "lte" : 2}}}, "filter" : {"terms" : {"uid" : ["123"]}}}}}}
json: map[constant_score:map[filter:map[bool:map[filter:map[terms:map[uid:[123]]]]]]]
any one knows why?