当前位置: 首页>>代码示例>>Golang>>正文


Golang lib.NewConn函数代码示例

本文整理汇总了Golang中github.com/mattbaird/elastigo/lib.NewConn函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConn函数的具体用法?Golang NewConn怎么用?Golang NewConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewConn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: readObject

func (e *esStateService) readObject(objid string) (o *object, err error) {
	conn := elastigo.NewConn()
	defer conn.Close()
	conn.Domain = e.stateDomain

	template := `{
		"query": {
			"term": {
				"object_id": "%v"
			}
		}
	}`
	tempbuf := fmt.Sprintf(template, objid)
	res, err := conn.Search(e.stateIndex, "geomodel_state", nil, tempbuf)
	if err != nil {
		return o, err
	}
	if res.Hits.Len() == 0 {
		return nil, nil
	}
	if res.Hits.Len() > 1 {
		return nil, fmt.Errorf("consistency failure, more than one object matched")
	}
	o = &object{}
	err = json.Unmarshal(*res.Hits.Hits[0].Source, o)
	if err != nil {
		return nil, err
	}

	return o, nil
}
开发者ID:ameihm0912,项目名称:geomodel,代码行数:31,代码来源:state.go

示例2: NewElastic

// Initializes a new elastic search handler.
func NewElastic(host string, index string) (*Elastic, error) {
	c := elastigo.NewConn()
	c.Domain = host
	b := c.NewBulkIndexer(10)
	b.Start()
	return &Elastic{c, b, index}, nil
}
开发者ID:sdgoij,项目名称:TheDistributedBay,代码行数:8,代码来源:elastic.go

示例3: InitElasticsearch

func InitElasticsearch() error {
	es = elastigo.NewConn()
	es.Domain = setting.Config.ElasticsearchDomain // needs to be configurable obviously
	es.Port = strconv.Itoa(setting.Config.ElasticsearchPort)
	if setting.Config.ElasticsearchUser != "" && setting.Config.ElasticsearchPasswd != "" {
		es.Username = setting.Config.ElasticsearchUser
		es.Password = setting.Config.ElasticsearchPasswd
	}
	if exists, err := es.ExistsIndex("definitions", "metric", nil); err != nil && err.Error() != "record not found" {
		return err
	} else {
		if !exists {
			_, err = es.CreateIndex("definitions")
			if err != nil {
				return err
			}
		}
		esopts := elastigo.MappingOptions{}

		err = es.PutMapping("definitions", "metric", MetricDefinition{}, esopts)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:splaspood,项目名称:raintank-metric,代码行数:27,代码来源:metricdef.go

示例4: StartElasticSearch

func (c *Configuration) StartElasticSearch() {

	address := c.Json.Elastic.HostAddress

	if !c.Json.RunLocalMode {
		if os.Getenv("CRASHMAT_ELASTICHOSTADDRESS") != "" {
			log.Println("Using environmental for CRASHMAT_ELASTICHOSTADDRESS")
			address = os.Getenv("CRASHMAT_ELASTICHOSTADDRESS")
		}
	}
	if c.Json.Elastic.DropAllOnStartUp {
		log.Println("Purging => ", address+"crashmat")
		out, err := exec.Command("curl", "-XDELETE", address+"crashmat").Output()
		if err != nil {
			log.Println(err)
		}
		fmt.Printf("%s", out)

		log.Println("Creating => ", address+"crashmat")
		out, err = exec.Command("curl", "-XPUT", address+"crashmat").Output()
		if err != nil {
			log.Println(err)
		}
	}

	elasticConnection := elastigo.NewConn()

	elasticConnection.SetFromUrl(address)

	ElasticConnection = elasticConnection
	c.ElasticConnection = elasticConnection
}
开发者ID:AlexsJones,项目名称:crashmat,代码行数:32,代码来源:configuration.go

示例5: NewServer

// NewServer returns a new instance of Server built from a config.
func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {

	elasticsearch := elastigo.NewConn()
	elasticsearch.SetFromUrl(c.Meta.ElasticSearchUrl)

	db := gocql.NewCluster(c.Database.CassandraNodes...)
	db.Keyspace = c.Database.CassandraKeyspace
	db.NumConns = c.Database.CassandraConns
	db.Discovery = gocql.DiscoveryConfig{
		DcFilter:   "",
		RackFilter: "",
		Sleep:      30 * time.Second,
	}

	s := &Server{
		buildInfo: *buildInfo,
		err:       make(chan error),
		closing:   make(chan struct{}),

		Hostname:      c.Meta.Hostname,
		BindAddress:   c.Meta.BindAddress,
		elasticsearch: elasticsearch,
		cassandra:     db,
	}

	// Append services.
	//s.appendMongoService(c.Mongo)

	s.appendMetricsReportingService(c.Meta)
	s.appendHTTPDService(c.HTTPD)
	s.appendRegistrationService(c.Registration, c.RegMeta)
	return s, nil
}
开发者ID:fkasper,项目名称:sitrep-authentication,代码行数:34,代码来源:server.go

示例6: Init

func Init() {
	host := setting.Cfg.Section("elasticsearch").Key("host").MustString("localhost")
	port := setting.Cfg.Section("elasticsearch").Key("port").MustInt64(9200)
	es = elastigo.NewConn()
	es.Domain = host
	es.Port = strconv.FormatInt(port, 10)
}
开发者ID:reduxdj,项目名称:grafana,代码行数:7,代码来源:elasticstore.go

示例7: main

func main() {
	c := elastigo.NewConn()
	log.SetFlags(log.LstdFlags)
	flag.Parse()

	fmt.Println("host = ", *host)
	// Set the Elasticsearch Host to Connect to
	c.Domain = *host

	// Index a document
	_, err := c.Index("testindex", "user", "docid_1", nil, `{"name":"bob"}`)
	exitIfErr(err)

	// Index a doc using a map of values
	_, err = c.Index("testindex", "user", "docid_2", nil, map[string]string{"name": "venkatesh"})
	exitIfErr(err)

	// Index a doc using Structs
	_, err = c.Index("testindex", "user", "docid_3", nil, MyUser{"wanda", 22})
	exitIfErr(err)

	// Search Using Raw json String
	searchJson := `{
	    "query" : {
	        "term" : { "Name" : "wanda" }
	    }
	}`
	out, err := c.Search("testindex", "user", nil, searchJson)
	if len(out.Hits.Hits) == 1 {
		fmt.Println("%v", out.Hits.Hits[0].Source)
	}
	exitIfErr(err)

}
开发者ID:jacqui,项目名称:elastigo,代码行数:34,代码来源:start_1.go

示例8: main

func main() {
	kingpin.Parse()

	r := Rss2{}

	response, err := http.DefaultClient.Get(*feedurl)
	if err != nil {
		log.Fatal(err)
	}

	xmlContent, err := ioutil.ReadAll(response.Body)
	err = xml.Unmarshal(xmlContent, &r)
	if err != nil {
		log.Fatal(err)
	}

	client := elastigo.NewConn()

	if *esurl != "" {
		client.SetFromUrl(*esurl)
	}

	for _, item := range r.ItemList {
		jsonValue, _ := json.MarshalIndent(item, "", "    ")
		if *esurl != "" {
			client.Index(*esindex, *estype, item.GUID, nil, jsonValue)
		} else {
			fmt.Println(string(jsonValue))
		}
	}
}
开发者ID:CodepopeWorking,项目名称:RuSShes,代码行数:31,代码来源:russhes.go

示例9: ExampleBulkIndexer_simple

// The simplest usage of background bulk indexing
func ExampleBulkIndexer_simple() {
	c := elastigo.NewConn()

	indexer := c.NewBulkIndexerErrors(10, 60)
	indexer.Start()
	indexer.Index("twitter", "user", "1", "", "", nil, `{"name":"bob"}`, true)
	indexer.Stop()
}
开发者ID:albertzak,项目名称:transporter,代码行数:9,代码来源:coreexample_test.go

示例10: GetInstance

func GetInstance(addr string, port int) *ElasticSearchStorage {
	c := elastigo.NewConn()
	c.Domain = addr
	c.Port = strconv.FormatInt(int64(port), 10)

	storage := &ElasticSearchStorage{connection: c}
	return storage
}
开发者ID:razorinc,项目名称:skydive,代码行数:8,代码来源:elasticsearch.go

示例11: Run

// connects to an NSQ topic and emits each message into streamtools.
func (b *ToElasticsearch) Run() {
	var err error
	var esIndex string
	var esType string

	conn := elastigo.NewConn()

	host := "localhost"
	port := "9200"

	for {
		select {
		case ruleI := <-b.inrule:
			host, err = util.ParseString(ruleI, "Host")
			if err != nil {
				b.Error(err)
				break
			}

			port, err = util.ParseString(ruleI, "Port")
			if err != nil {
				b.Error(err)
				break
			}

			esIndex, err = util.ParseString(ruleI, "Index")
			if err != nil {
				b.Error(err)
				break
			}

			esType, err = util.ParseString(ruleI, "Type")
			if err != nil {
				b.Error(err)
				break
			}

			conn.Domain = host
			conn.Port = port

		case msg := <-b.in:
			_, err := conn.Index(esIndex, esType, "", nil, msg)
			if err != nil {
				b.Error(err)
			}
		case <-b.quit:
			return
		case c := <-b.queryrule:
			c <- map[string]interface{}{
				"Host":  host,
				"Port":  port,
				"Index": esIndex,
				"Type":  esType,
			}
		}
	}
}
开发者ID:harrisj,项目名称:streamtools,代码行数:58,代码来源:toElasticsearch.go

示例12: SearchConnection

func (bdb *BloomDatabase) SearchConnection() *elastigo.Conn {
	if bdb.sharedSearch == nil {
		conn := elastigo.NewConn()
		conn.SetHosts(bdb.searchHosts)
		bdb.sharedSearch = conn
	}

	return bdb.sharedSearch
}
开发者ID:untoldone,项目名称:bloomapi,代码行数:9,代码来源:bloomdb.go

示例13: writeObject

func (e *esStateService) writeObject(o object) (err error) {
	conn := elastigo.NewConn()
	defer conn.Close()
	conn.Domain = e.stateDomain
	_, err = conn.Index(e.stateIndex, "geomodel_state", o.ObjectID, nil, o)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:ameihm0912,项目名称:geomodel,代码行数:10,代码来源:state.go

示例14: InitElasticsearch

func InitElasticsearch() error {
	es = elastigo.NewConn()
	es.Domain = setting.Config.ElasticsearchDomain // needs to be configurable obviously
	es.Port = strconv.Itoa(setting.Config.ElasticsearchPort)
	if setting.Config.ElasticsearchUser != "" && setting.Config.ElasticsearchPasswd != "" {
		es.Username = setting.Config.ElasticsearchUser
		es.Password = setting.Config.ElasticsearchPasswd
	}

	return nil
}
开发者ID:splaspood,项目名称:raintank-metric,代码行数:11,代码来源:eventdef.go

示例15: NewExtendedEssConn

/*
   Create the index if it does not exist.
   Optionally apply a mapping if mapping file is supplied.
*/
func NewExtendedEssConn(esshost string, essport int) *ExtendedEssConn {

	ed := ExtendedEssConn{
		Conn: elastigo.NewConn(),
	}

	ed.Domain = esshost
	ed.Port = fmt.Sprintf("%d", essport)

	return &ed
}
开发者ID:vindalu,项目名称:vindalu,代码行数:15,代码来源:ess.go


注:本文中的github.com/mattbaird/elastigo/lib.NewConn函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。