-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (34 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"net/http"
"strings"
"github.com/grokify/mogo/fmt/fmtutil"
"github.com/grokify/mogo/log/logutil"
"github.com/grokify/mogo/net/http/httpsimple"
"github.com/grokify/goelastic"
"github.com/grokify/goelastic/docs/reference"
"github.com/grokify/goelastic/models/es5"
)
// Example from:
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
// main shows bool query in action
func main() {
esClient, err := goelastic.NewSimpleClient("", "", "", true)
logutil.FatalErr(err)
body := es5.QueryBody{
Query: es5.Query{
Bool: &es5.BoolQuery{
Should: []es5.Filter{
{Match: map[string]string{"hash_tags": "wow"}},
{Match: map[string]string{"hash_tags": "elasticsearch"}}},
MinimumShouldMatch: 1}}}
fmtutil.MustPrintJSON(body)
resp, err := esClient.Do(httpsimple.Request{
Method: http.MethodPost,
URL: strings.Join([]string{"twitter/tweet", goelastic.SlugSearch}, "/"),
BodyType: httpsimple.BodyTypeJSON,
Body: body})
reference.ProcResponse(resp, err)
fmt.Println("DONE")
}