diff --git a/utils/reassign_topics/elastic.go b/utils/reassign_topics/elastic.go new file mode 100644 index 0000000..21bfa59 --- /dev/null +++ b/utils/reassign_topics/elastic.go @@ -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 +} diff --git a/utils/reassign_topics/main.go b/utils/reassign_topics/main.go new file mode 100644 index 0000000..875a74b --- /dev/null +++ b/utils/reassign_topics/main.go @@ -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) +}