Es 自由查询
Yes. That's how it works. RawStringQuery is a query, not the message body. As such, you use it like you'd do with any query:
package main
import (
    "fmt"
    "gopkg.in/olivere/elastic.v3"
)
func main() {
    client, err := elastic.NewClient()
    if err != nil {
        panic(err)
    }
    s := `{"match_all":{}}`
    res, err := client.Search().
        Index("store2").
        Query(elastic.RawStringQuery(s)).
        Sort("price", true).
        Do()
    if err != nil {
        panic(err)
    }
    fmt.Printf("%d results\n", res.TotalHits)
}
If you want to pass raw JSON and send it as the body for your request, this does the job:
package main
import (
    "fmt"
    "gopkg.in/olivere/elastic.v3"
)
func main() {
    client, err := elastic.NewClient()
    if err != nil {
        panic(err)
    }
    s := `{"query":{"match_all":{}},"sort":[{"price":{"order":"asc"}}]}`
    res, err := client.Search().
        Index("store2").
        Source(s).
        Do()
    if err != nil {
        panic(err)
    }
    fmt.Printf("%d results\n", res.TotalHits)
}
posted on 2020-05-20 17:12 ExplorerMan 阅读(282) 评论(0) 收藏 举报
 
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号