"query": {
"bool": {
"must":
{
"bool": {
"should":
{
"match": {
"privileged": {
"query":true
}
}
}
}
}
}
}
代码如下:
package main
import (
"encoding/json"
"github.com/olivere/elastic/v7"
"log"
)
func main () {
es()
}
func es() {
q := elastic.NewBoolQuery()
q = q.Must(elastic.NewBoolQuery().Should(elastic.NewMatchQuery("privileged", true)))
src, err := q.Source()
if err != nil {
log.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
log.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
log.Println(got)
}