Created
October 31, 2018 17:20
-
-
Save deadcheat/6d63dbecb1aa5959702a437faca20556 to your computer and use it in GitHub Desktop.
自分用ESのIdsクエリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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