首页 > 其他 > 详细

Es 自由查询

时间:2020-05-20 19:32:58      阅读:68      评论:0      收藏:0      [点我收藏+]

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)
}

Es 自由查询

原文:https://www.cnblogs.com/ExMan/p/12924755.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!