• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang lib.NewConn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: main

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

	// Trace all requests
	c.RequestTracer = func(method, url, body string) {
		log.Printf("Requesting %s %s", method, url)
		log.Printf("Request body: %s", body)
	}

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

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

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

	// Index a doc using Structs
	_, err = c.Index("testindex", "user", "docid_3", nil, map[string]string{"name": "wena"})
	exitIfErr(err)

	// "name":"peanuts","description":"Honey Roasted peanuts","permalink":"",
	//             "tax_category_id":0,"shipping_category_id":0,"deleted_at":"0001-01-01T00:00:00Z","meta_description":"",
	//             "meta_keywords":"","position":0,"is_featured":false,"can_discount":false,"distributor_only_membership":false

	// product := models.Product{ 59001, "peanuts", "Honey Roasted peanuts", "Good taste food"}
	//
	//
	// // Index a doc using Structs
	// _, err = c.Index("pdtindex", "product", "producid_3", nil, product)
	//     fmt.Println(product)

	//exitIfErr(err)

	// Search Using Raw json String
	searchJson := `{
	    "query" : {
	        "term" : { "Name" : "venkatesh" }
	    }
	}`
	out, err := c.Search("oldindex", "product", nil, searchJson)

	if len(out.Hits.Hits) == 1 {
		fmt.Println("%v", out.Hits.Hits[0].Source)
	}
	exitIfErr(err)

}
开发者ID:hustbill,项目名称:post-message-service,代码行数:54,代码来源:searchIndex.go


示例17: NewESClient

func NewESClient() DbClient {
	conn := elastigo.NewConn()
	host := eshost1
	conn.Domain = host

	batchconn := goes.NewConnection(host, "9200")
	return &ESClient{
		conn:      conn,
		batchconn: batchconn,
	}
}
开发者ID:sundy-li,项目名称:dbstattest,代码行数:11,代码来源:es.go


示例18: GetConnection

func (elasticSearchClient *ElasticSearchClient) GetConnection() *elastigo.Conn {
	if elasticSearchClient.connection != nil {
		return elasticSearchClient.connection
	} else {
		c := elastigo.NewConn()
		c.SetHosts(elasticSearchClient.host)
		c.SetPort(strconv.Itoa(elasticSearchClient.port))

		elasticSearchClient.connection = c
		return elasticSearchClient.connection
	}
}
开发者ID:cloudawan,项目名称:cloudone_utility,代码行数:12,代码来源:elasticsearch_client.go


示例19: NSQToES

// Consumes messages from NSQ and publishes to ElasticSearch
func NSQToES() error {
	nc, err := nsq.NewConsumer(Topic, Channel, nsq.NewConfig())
	if err != nil {
		return err
	}
	tn := &nsqToES{
		conn: el.NewConn(),
	}
	tn.conn.Domain = ESAddress

	nc.AddConcurrentHandlers(tn, NumHandlers)
	return nc.ConnectToNSQD(NSQAddress)
}
开发者ID:asim,项目名称:archiver,代码行数:14,代码来源:slack.go


示例20: Configure

// Configure initializes this producer with values from a plugin config.
func (prod *ElasticSearch) Configure(conf core.PluginConfig) error {
	err := prod.ProducerBase.Configure(conf)
	if err != nil {
		return err
	}

	prod.SetStopCallback(prod.close)

	defaultServer := []string{"localhost"}
	numConnections := conf.GetInt("Connections", 6)
	retrySec := conf.GetInt("RetrySec", 5)

	prod.conn = elastigo.NewConn()
	prod.conn.Hosts = conf.GetStringArray("Servers", defaultServer)
	prod.conn.Domain = conf.GetString("Domain", prod.conn.Hosts[0])
	prod.conn.ClusterDomains = prod.conn.Hosts
	prod.conn.Port = strconv.Itoa(conf.GetInt("Port", 9200))
	prod.conn.Username = conf.GetString("User", "")
	prod.conn.Password = conf.GetString("Password", "")

	prod.indexer = prod.conn.NewBulkIndexerErrors(numConnections, retrySec)
	prod.indexer.BufferDelayMax = time.Duration(conf.GetInt("BatchTimeoutSec", 5)) * time.Second
	prod.indexer.BulkMaxBuffer = conf.GetInt("BatchSizeByte", 32768)
	prod.indexer.BulkMaxDocs = conf.GetInt("BatchMaxCount", 128)

	prod.indexer.Sender = func(buf *bytes.Buffer) error {
		_, err := prod.conn.DoCommand("POST", "/_bulk", nil, buf)
		if err != nil {
			Log.Error.Print("ElasticSearch response error - ", err)
		}
		return err
	}

	prod.index = conf.GetStreamMap("Index", "")
	prod.msgType = conf.GetStreamMap("Type", "log")
	prod.msgTTL = conf.GetString("TTL", "")
	prod.dayBasedIndex = conf.GetBool("DayBasedIndex", false)

	prod.counters = make(map[string]*int64)
	prod.lastMetricUpdate = time.Now()

	for _, index := range prod.index {
		shared.Metric.New(elasticMetricMessages + index)
		shared.Metric.New(elasticMetricMessagesSec + index)
		prod.counters[index] = new(int64)
	}

	prod.SetCheckFuseCallback(prod.isClusterUp)
	return nil
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:51,代码来源:elasticsearch.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang api.AddSessionToCache函数代码示例发布时间:2022-05-23
下一篇:
Golang core.SearchRequest函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap