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


Golang core.Index函数代码示例

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


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

示例1: handlePacket

func handlePacket(buffer []byte) {
	parser := rfc5424.NewParser(buffer)
	err := parser.Parse()

	if err != nil {
		fmt.Printf("Error reading syslog message %s", err)
		return
	}

	log := parser.Dump()
	log["@timestamp"] = log["timestamp"]
	log["facility_label"] = FACILITY_LABELS[(log["facility"]).(int)]
	log["severity_label"] = SEVERITY_LABELS[(log["severity"]).(int)]
	log["type"] = "syslog"

	now := time.Now()
	index := "logstash-" + now.Format("2006.01.02")

	_, err = elasticSearch.Index(true, index, "logs", "", log)
	if err != nil {
		fmt.Printf("Error indexing message %s", err)
		return
	}
	fmt.Println("Logged")
}
开发者ID:postfix,项目名称:logflume,代码行数:25,代码来源:logflume.go

示例2: main

func main() {
	core.DebugRequests = true
	log.SetFlags(log.LstdFlags)
	flag.Parse()

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

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

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

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

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

}
开发者ID:pombredanne,项目名称:vossibility-bulletin,代码行数:34,代码来源:start_1.go

示例3: main

func main() {

	type Address struct {
		ProvinceName string `json:"province_name"`
	}

	api.Domain = "localhost"
	//api.Port = "9300"

	core.Index("data", "address", "1", nil, Address{"ประเทศไทย"})
	core.Index("data", "address", "2", nil, Address{"เพลงไทย"})

}
开发者ID:up1,项目名称:go-elasticsearch,代码行数:13,代码来源:index.go

示例4: PublishMysqlTransaction

func (publisher *PublisherType) PublishMysqlTransaction(t *MysqlTransaction) error {
	// Set the Elasticsearch Host to Connect to
	api.Domain = publisher.mother_host
	api.Port = publisher.mother_port

	index := fmt.Sprintf("packetbeat-%d.%02d.%02d", t.ts.Year(), t.ts.Month(), t.ts.Day())

	status := t.Mysql["error_message"].(string)
	if len(status) == 0 {
		status = "OK"
	}

	src_server := publisher.GetServerName(t.Src.Ip)
	dst_server := publisher.GetServerName(t.Dst.Ip)

	// add Mysql transaction
	_, err := core.Index(index, "mysql", "", nil, Event{
		t.ts, "mysql", t.Src.Ip, t.Src.Port, t.Src.Proc, "", src_server,
		t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
		t.ResponseTime, status, t.Request_raw, t.Response_raw,
		t.Mysql, nil, nil})

	DEBUG("publish", "Sent MySQL transaction [%s->%s]:\n%s", t.Src.Proc, t.Dst.Proc, t.Mysql)

	return err

}
开发者ID:nanderoo,项目名称:packetbeat,代码行数:27,代码来源:publish.go

示例5: PublishRedisTransaction

func (publisher *PublisherType) PublishRedisTransaction(t *RedisTransaction) error {
	var err error
	index := fmt.Sprintf("packetbeat-%d.%02d.%02d", t.ts.Year(), t.ts.Month(), t.ts.Day())

	status := "OK"

	src_server := publisher.GetServerName(t.Src.Ip)
	dst_server := publisher.GetServerName(t.Dst.Ip)

	if _Config.Agent.Ignore_outgoing && dst_server != "" &&
		dst_server != publisher.name {
		// duplicated transaction -> ignore it
		DEBUG("publish", "Ignore duplicated REDIS transaction on %s: %s -> %s", publisher.name, src_server, dst_server)
		return nil
	}

	event := Event{
		t.ts, "redis", t.Src.Ip, t.Src.Port, t.Src.Proc, "", src_server,
		t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
		t.ResponseTime, status, t.Request_raw, t.Response_raw,
		nil, nil, t.Redis}

	if IS_DEBUG("publish") {
		PrintPublishEvent(&event)
	}

	// add Redis transaction
	if !publisher.disabled {
		_, err = core.Index(index, "redis", "", nil, event)
	}

	return err
}
开发者ID:Bengt,项目名称:packetbeat,代码行数:33,代码来源:publish.go

示例6: main

func main() {
	api.Domain = "localhost"

	// connect to ZeroMQ
	subscriber, _ := zmq.NewSocket(zmq.SUB)
	defer subscriber.Close()
	subscriber.Connect("tcp://38.86.38.213:12777")
	// subscriber.Connect("tcp://127.0.0.1:12777")
	subscriber.SetSubscribe("")

	// endless looping!
	for {
		var p Packet

		// get stuff from ZeroMQ
		msg, _ := subscriber.Recv(0)
		// fmt.Println(msg)

		// decode the JSON aprs packet in to struct p
		err := json.Unmarshal([]byte(msg), &p)
		log.Println(err)

		// re-encode digipeters back to json
		// digipeters, err := json.Marshal(p.Digipeaters)
		// wx, err := json.Marshal(p.Wx)

		t := time.Now()
		response, _ := core.Index("packets", "packet", "", t, p)

		fmt.Println(response)
	}
}
开发者ID:hamli,项目名称:aprs-save,代码行数:32,代码来源:aprs-save.go

示例7: CreateGeoJotHandler

func CreateGeoJotHandler(w http.ResponseWriter, r *http.Request) {
	// Parse the incoming geojot from the request body
	var geojotJSON GeoJotJSON
	err := json.NewDecoder(r.Body).Decode(&geojotJSON)
	if err != nil {
		serveError(w, err)
	}

	geojot := geojotJSON.GeoJot

	// add single go struct entity
	response, _ := core.Index(true, es_index, es_index_type, "", geojot)

	// Grab the Id for the client
	geojot.Id = response.Id

	// Serialize the modified geojot to JSON
	j, err := json.Marshal(GeoJotJSON{GeoJot: geojot})
	if err != nil {
		serveError(w, err)
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(j)
}
开发者ID:jbasdf,项目名称:go_chat,代码行数:25,代码来源:geo_jots.go

示例8: main

// for testing
func main() {
	flag.Parse()
	log.SetFlags(log.Ltime | log.Lshortfile)
	api.Domain = *eshost
	response, _ := core.Index(true, "twitter", "tweet", "1", NewTweet("kimchy", "Search is cool"))
	indices.Flush()
	log.Printf("Index OK: %v", response.Ok)
	searchresponse, err := core.SearchRequest(true, "twitter", "tweet", "{\"query\" : {\"term\" : { \"user\" : \"kimchy\" }}}", "", 0)
	if err != nil {
		log.Println("error during search:" + err.Error())
		log.Fatal(err)
	}
	// try marshalling to tweet type
	var t Tweet
	json.Unmarshal(searchresponse.Hits.Hits[0].Source, t)
	log.Printf("Search Found: %s", t)
	response, _ = core.Get(true, "twitter", "tweet", "1")
	log.Printf("Get: %v", response.Exists)
	exists, _ := core.Exists(true, "twitter", "tweet", "1")
	log.Printf("Exists: %v", exists)
	indices.Flush()
	countResponse, _ := core.Count(true, "twitter", "tweet")
	log.Printf("Count: %v", countResponse.Count)
	response, _ = core.Delete(true, "twitter", "tweet", "1", -1, "")
	log.Printf("Delete OK: %v", response.Ok)
	response, _ = core.Get(true, "twitter", "tweet", "1")
	log.Printf("Get: %v", response.Exists)

	healthResponse, _ := cluster.Health(true)
	log.Printf("Health: %v", healthResponse.Status)

	cluster.State("transient", "discovery.zen.minimum_master_nodes", 2)

}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:35,代码来源:client.go

示例9: Run

// Run is the block's main loop. Here we listen on the different channels we set up.
// This block posts a message to a specified Elasticsearch index with the given type.
func (b *ToElasticsearch) Run() {
	var err error
	var index string
	var indextype string

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

	for {
		select {
		case msgI := <-b.inrule:
			host, err = util.ParseString(msgI, "Host")
			if err != nil {
				b.Error(err)
				continue
			}
			port, err = util.ParseString(msgI, "Port")
			if err != nil {
				b.Error(err)
				continue
			}
			index, err = util.ParseString(msgI, "Index")
			if err != nil {
				b.Error(err)
				continue
			}
			indextype, err = util.ParseString(msgI, "IndexType")
			if err != nil {
				b.Error(err)
				continue
			}

			// Set the Elasticsearch Host/Port to Connect to
			api.Domain = host
			api.Port = port

		case MsgChan := <-b.queryrule:
			// deal with a query request
			MsgChan <- map[string]interface{}{
				"Host":      host,
				"Port":      port,
				"Index":     index,
				"IndexType": indextype,
			}
		case <-b.quit:
			// quit the block
			return
		case msg := <-b.in:
			var args map[string]interface{}
			_, err := core.Index(index, indextype, "", args, msg)
			if err != nil {
				b.Error(err)
			}
		}
	}
}
开发者ID:josephwinston,项目名称:streamtools,代码行数:58,代码来源:toElasticsearch.go

示例10: Put

// value should be JSON serializable.
func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
	id := d.KeyHash(key)
	res, err := core.Index(false, d.Index(key), key.Type(), id, value)
	if err != nil {
		return err
	}
	if !res.Ok {
		return fmt.Errorf("Elasticsearch response: NOT OK. %v", res)
	}
	return nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:12,代码来源:datastore.go

示例11: DispatchLogs

func DispatchLogs(es eventsource.EventSource) {
	for {
		log := <-LogPipe
		resp, err := core.Index(true, "logs", "log", "", log)
		if err != nil {
			fmt.Println("EINDEXING: ", err)
		} else {
			es.SendMessage(log.URL, "", resp.Id) // I should add a type
			indices.Flush()
		}
	}
}
开发者ID:jeromenerf,项目名称:snitch.go,代码行数:12,代码来源:snitch.go

示例12: doSyncUsers

// doSyncUsers synchronize the content of the specified user file with the
// Elastic Search backend.
func doSyncUsers(c *cli.Context) {
	_ = ParseConfigOrDie(c.GlobalString("config"))

	var userData map[string]UserData
	if _, err := toml.DecodeFile(c.String("file"), &userData); err != nil {
		log.Fatal(err)
	}

	for login, data := range userData {
		fmt.Printf("Saving data for %q: %#v\n", login, data)
		if _, err := core.Index(UserIndex, UserType, login, nil, data); err != nil {
			log.Errorf("indexing data for %q; %v", login, err)
		}
	}
}
开发者ID:JacquesPerrault,项目名称:vossibility-collector,代码行数:17,代码来源:users.go

示例13: PublishHttpTransaction

func (publisher *PublisherType) PublishHttpTransaction(t *HttpTransaction) error {
	// Set the Elasticsearch Host to Connect to
	api.Domain = publisher.mother_host
	api.Port = publisher.mother_port

	index := fmt.Sprintf("packetbeat-%d.%02d.%02d", t.ts.Year(), t.ts.Month(), t.ts.Day())

	status := t.Http["response"].(bson.M)["phrase"].(string)

	src_server := publisher.GetServerName(t.Src.Ip)
	dst_server := publisher.GetServerName(t.Dst.Ip)

	if _Config.Agent.Ignore_outgoing && dst_server != "" &&
		dst_server != publisher.name {
		// duplicated transaction -> ignore it
		DEBUG("publish", "Ignore duplicated HTTP transaction on %s: %s -> %s", publisher.name, src_server, dst_server)
		return nil
	}

	var src_country = ""
	if _GeoLite != nil {
		if len(src_server) == 0 { // only for external IP addresses
			loc := _GeoLite.GetLocationByIP(t.Src.Ip)
			if loc != nil {
				src_country = loc.CountryCode
			}
		}
	}

	event := Event{
		t.ts, "http", t.Src.Ip, t.Src.Port, t.Src.Proc, src_country, src_server,
		t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
		t.ResponseTime, status, t.Request_raw, t.Response_raw,
		nil, t.Http, nil}

	if IS_DEBUG("publish") {
		PrintPublishEvent(&event)
	}

	// add Http transaction
	_, err := core.Index(index, "http", "", nil, event)

	return err

}
开发者ID:NanXiao,项目名称:packetbeat,代码行数:45,代码来源:publish.go

示例14: ToElasticsearch

// Posts a message to a specified Elasticsearch index with the given type.
func ToElasticsearch(b *Block) {

	type toElasticsearchRule struct {
		Host  string
		Port  string
		Index string
		Type  string
	}

	var rule *toElasticsearchRule

	// TODO check the endpoint for happiness
	for {
		select {
		case msg := <-b.Routes["set_rule"]:
			if rule == nil {
				rule = &toElasticsearchRule{}
			}
			unmarshal(msg, rule)
			// Set the Elasticsearch Host/Port to Connect to
			api.Domain = rule.Host
			api.Port = rule.Port

		case msg := <-b.Routes["get_rule"]:
			if rule == nil {
				marshal(msg, &toElasticsearchRule{})
			} else {
				marshal(msg, rule)
			}
		case <-b.QuitChan:
			quit(b)
			return
		case msg := <-b.InChan:
			if rule == nil {
				break
			}

			_, err := core.Index(true, rule.Index, rule.Type, "", msg.Msg)
			if err != nil {
				log.Println(err.Error())
				break
			}
		}
	}
}
开发者ID:harlo,项目名称:streamtools,代码行数:46,代码来源:toElasticsearch.go

示例15: PublishEvent

func (publisher *PublisherType) PublishEvent(ts time.Time, src *Endpoint, dst *Endpoint, event *Event) error {
	index := fmt.Sprintf("packetbeat-%d.%02d.%02d", ts.Year(), ts.Month(), ts.Day())

	event.Src_server = publisher.GetServerName(src.Ip)
	event.Dst_server = publisher.GetServerName(dst.Ip)

	if _Config.Agent.Ignore_outgoing && event.Dst_server != "" &&
		event.Dst_server != publisher.name {
		// duplicated transaction -> ignore it
		DEBUG("publish", "Ignore duplicated REDIS transaction on %s: %s -> %s", publisher.name, event.Src_server, event.Dst_server)
		return nil
	}

	event.Timestamp = ts
	event.Src_ip = src.Ip
	event.Src_port = src.Port
	event.Src_proc = src.Proc
	event.Dst_ip = dst.Ip
	event.Dst_port = dst.Port
	event.Dst_proc = dst.Proc

	// set src_country if no src_server is set
	event.Src_country = ""
	if _GeoLite != nil {
		if len(event.Src_server) == 0 { // only for external IP addresses
			loc := _GeoLite.GetLocationByIP(src.Ip)
			if loc != nil {
				event.Src_country = loc.CountryCode
			}
		}
	}

	if IS_DEBUG("publish") {
		PrintPublishEvent(event)
	}

	// add Redis transaction
	var err error
	if !publisher.disabled {
		_, err = core.Index(index, event.Type, "", nil, event)
	}

	return err
}
开发者ID:joshboon,项目名称:packetbeat,代码行数:44,代码来源:publish.go


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