mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 10:44:17 +02:00
- dont show ccr status if license insufficient - add automated tests - fix config loading - fix search output - fix `license show` panics - fix `ilm show` completion - print ask passwd prompt to stderr
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
/*
|
|
Copyright © 2026 Thomas von Dein
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package printer
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
|
|
"codeberg.org/scip/esctl/pkg/cfg"
|
|
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func PrintDocs(conf *cfg.Config, hits []types.Hit) {
|
|
if !conf.Ascending {
|
|
slices.Reverse(hits)
|
|
}
|
|
|
|
for _, hit := range hits {
|
|
PrintDoc(conf, hit)
|
|
}
|
|
|
|
}
|
|
|
|
func PrintDoc(conf *cfg.Config, hit types.Hit) {
|
|
var score types.Float64
|
|
if hit.Score_ != nil {
|
|
score = *hit.Score_
|
|
}
|
|
|
|
docjson := fmt.Sprintf(`{"id":"%s", "score":%0.4f, "index":"%s", "source":%s}`,
|
|
*hit.Id_,
|
|
score,
|
|
hit.Index_,
|
|
hit.Source_)
|
|
|
|
if conf.Path != "" {
|
|
value := gjson.Get(docjson, conf.Path)
|
|
fmt.Println(value.String())
|
|
} else {
|
|
fmt.Println(docjson)
|
|
}
|
|
}
|