Skip to content

Instantly share code, notes, and snippets.

@deadcheat
Created October 31, 2018 17:20
Show Gist options
  • Save deadcheat/6d63dbecb1aa5959702a437faca20556 to your computer and use it in GitHub Desktop.
Save deadcheat/6d63dbecb1aa5959702a437faca20556 to your computer and use it in GitHub Desktop.
自分用ESのIdsクエリ
package main
import (
"context"
"fmt"
"github.com/olivere/elastic"
)
func main() {
c, err := elastic.NewSimpleClient(
elastic.SetURL("http://localhost:9200"),
)
if err != nil {
panic(err)
}
defer c.Stop()
q := elastic.NewIdsQuery("_doc").Ids("1", "2")
result, err := c.Search("sample").Index("sample").Query(q).Do(context.Background())
fmt.Printf("%+v \n", result.Hits)
for i := 0; i < int(result.Hits.TotalHits); i++ {
d, _ := result.Hits.Hits[i].Source.MarshalJSON()
fmt.Printf("%d %+v \n", i, string(d))
}
fmt.Println(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment