Skip to content

Commit f7dd289

Browse files
Дмитрий БережновДмитрий Бережнов
Дмитрий Бережнов
authored and
Дмитрий Бережнов
committed
feat(api): add JSON eXtract feature
1 parent ec807e3 commit f7dd289

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

modules/router/methods.go

+21-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"encoding/json"
1818
"errors"
1919
"fmt"
20-
"github.com/davecgh/go-spew/spew"
2120
"io/ioutil"
2221
"log"
2322
"net/http"
@@ -385,27 +384,37 @@ func (rt *Router) saveHintsToJsonFile(request apiRequest) error {
385384
}
386385
defer f.Close()
387386

388-
i := 0
387+
scrollId := ""
389388
for {
390-
if i > 3 {
391-
break
392-
}
393-
fmt.Println(">>>>", i, req)
394-
sresponse, err := rt.doPost(host+request.Search.Index+"/_search?scroll=10m", req, "Search")
395-
if err != nil {
396-
return err
389+
sresponse := []byte{}
390+
if scrollId == "" {
391+
r, err := rt.doPost(host+request.Search.Index+"/_search?scroll=10m", req, "Search")
392+
if err != nil {
393+
return err
394+
}
395+
sresponse = r
396+
} else {
397+
scroll := map[string]interface{}{"scroll": "10m", "scroll_id": scrollId}
398+
r, err := rt.doPost(host+"_search/scroll", scroll, "Search")
399+
if err != nil {
400+
return err
401+
}
402+
sresponse = r
397403
}
398404

399405
err = json.Unmarshal(sresponse, &scrollresponse)
400406
if err != nil {
401407
return err
402408
}
403409

404-
spew.Println("Hints total", scrollresponse.HitsRoot.Total.Value)
405-
spew.Println("Hints req len", len(scrollresponse.HitsRoot.Hits))
406-
spew.Println("ScrollID", scrollresponse.ScrollID)
410+
scrollId = scrollresponse.ScrollID
411+
412+
log.Println("Hints total", scrollresponse.HitsRoot.Total.Value)
413+
log.Println("Hints req len", len(scrollresponse.HitsRoot.Hits))
414+
log.Println("scrollId", scrollId)
407415

408416
if len(scrollresponse.HitsRoot.Hits) == 0 {
417+
log.Println("Search is done!")
409418
break
410419
}
411420

@@ -440,12 +449,6 @@ func (rt *Router) saveHintsToJsonFile(request apiRequest) error {
440449
f.WriteString(string(jsonData) + "\n")
441450

442451
}
443-
444-
if scrollresponse.ScrollID != "" {
445-
//req = map[string]interface{}{"scroll": "10m", "scroll_id": scrollresponse.ScrollID}
446-
}
447-
448-
i = i + 1
449452
}
450453

451454
return nil

0 commit comments

Comments
 (0)