ぶろぐ

日記です

golangからcloudsearchを使う


sdk install

go get github.com/aws/aws-sdk-go/...

example code

package main

import (
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudsearchdomain"
)

func main() {
	svc := cloudsearchdomain.New(session.New(&aws.Config{
		Region:   aws.String("ap-northeast-1"),
		Endpoint: aws.String("http://search-XXXX.ap-northeast-1.cloudsearch.amazonaws.com"),
	}))

	params := &cloudsearchdomain.SearchInput{
		Query: aws.String("Iron Man 2"),
	}
	resp, err := svc.Search(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(resp)
}

run

go run cloudsearch.go
{
  Hits: {
    Found: 1,
    Hit: [{
        Fields: {
          running_time_secs: ["7440"],
          image_url: ["http://ia.media-imdb.com/images/M/MV5BMTM0MDgwNjMyMl5BMl5BanBnXkFtZTcwNTg3NzAzMw@@._V1_SX400_.jpg"],
          rank: ["276"],
          directors: ["Jon Favreau"],
          actors: ["Robert Downey Jr.","Mickey Rourke","Gwyneth Paltrow"],
          rating: ["7.0"],
          genres: ["Action","Adventure","Sci-Fi"],
          plot: ["Tony Stark has declared himself Iron Man and installed world peace... or so he thinks. He soon realizes that not only is there a mad man out to kill him with his own technology, but there's something more: he is dying."],
          title: ["Iron Man 2"],
          year: ["2010"],
          release_date: ["2010-04-26T00:00:00Z"]
        },
        Id: "tt1228705"
      }],
    Start: 0
  },
  Status: {
    Rid: "uZ/D68sqFQp5O20=",
    Timems: 12
  }
}