Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 29, 2015 14:01
Show Gist options
  • Save up1/62f3b65b7266ca75fb78 to your computer and use it in GitHub Desktop.
Save up1/62f3b65b7266ca75fb78 to your computer and use it in GitHub Desktop.
ElasticSearch with Go
package main
import "github.com/mattbaird/elastigo/api"
import "github.com/mattbaird/elastigo/core"
func main() {
type Address struct {
ProvinceName string `json:"province_name"`
}
api.Domain = "localhost"
core.Index("data", "address", "1", nil, Address{"ประเทศไทย"})
core.Index("data", "address", "2", nil, Address{"เพลงไทย"})
}
package main
import "github.com/mattbaird/elastigo/api"
import "github.com/mattbaird/elastigo/core"
import "fmt"
func main() {
type Address struct {
ProvinceName string `json:"province_name"`
}
api.Domain = "localhost"
searchJson := `{"query":{"match":{"province_name":"ไทย"}}}`
out, _ := core.SearchRequest("data", "address", nil, searchJson)
for i:= 0; i<len(out.Hits.Hits); i++ {
fmt.Printf("%s\n", out.Hits.Hits[i].Source)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment