Reassign topics initial
This commit is contained in:
parent
2ab75b4ed9
commit
2cfdf22dfa
51
utils/reassign_topics/elastic.go
Normal file
51
utils/reassign_topics/elastic.go
Normal file
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import "gitea.difrex.ru/Umbrella/fetcher/i2es"
|
||||
import "fmt"
|
||||
import "net/http"
|
||||
import log "github.com/Sirupsen/logrus"
|
||||
import "encoding/json"
|
||||
|
||||
type Conf struct {
|
||||
ES i2es.ESConf
|
||||
Step int
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
Indices IndexStats `json:"indices"`
|
||||
}
|
||||
|
||||
type IndexStats map[string]interface{}
|
||||
|
||||
// "indices": {
|
||||
// "idec": {
|
||||
// "uuid": "_dO3GVkoSA665CdyV5LLlQ",
|
||||
// "primaries": {
|
||||
// "docs": {
|
||||
// "count": 5600,
|
||||
// "deleted": 435
|
||||
// }
|
||||
|
||||
func (c *Conf) getDocsCount() int64 {
|
||||
reqURL := fmt.Sprintf("%s/%s/_stats", c.ES.Host, c.ES.Index)
|
||||
req, err := http.NewRequest("GET", reqURL, nil)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return -1
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
var stats Stats
|
||||
err = json.NewDecoder(resp.Body).Decode(&stats)
|
||||
log.Infof("%+v", stats)
|
||||
|
||||
return -1
|
||||
}
|
36
utils/reassign_topics/main.go
Normal file
36
utils/reassign_topics/main.go
Normal file
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"fmt"
|
||||
|
||||
"gitea.difrex.ru/Umbrella/fetcher/i2es"
|
||||
)
|
||||
|
||||
var (
|
||||
es, index, esType string
|
||||
step int
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&es, "es", "http://127.0.0.1:9200", "Elasticsearch URL")
|
||||
flag.StringVar(&index, "index", "idec", "Elasticsearch index")
|
||||
flag.StringVar(&esType, "esType", "post", "Elasticsearch document type")
|
||||
flag.IntVar(&step, "step", 100, "Scroll step")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
conf := Conf{
|
||||
ES: i2es.ESConf{
|
||||
Host: es,
|
||||
Index: index,
|
||||
Type: esType,
|
||||
},
|
||||
Step: step,
|
||||
}
|
||||
|
||||
count := conf.getDocsCount()
|
||||
fmt.Println(count)
|
||||
}
|
Loading…
Reference in New Issue
Block a user