Reassign topics initial

This commit is contained in:
Denis Zheleztsov 2018-11-11 11:59:58 +03:00
parent 2ab75b4ed9
commit 2cfdf22dfa
Signed by: Difrex
GPG Key ID: B047A0E62A285621
2 changed files with 87 additions and 0 deletions

View 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
}

View 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)
}