enhancement(search): group opensearch related files together, housekeeping

This commit is contained in:
fschade
2025-07-31 18:50:27 +02:00
parent 5abfd1744e
commit a7d4ff4872
14 changed files with 16 additions and 26 deletions

View File

@@ -1,14 +1,11 @@
package opensearch
import (
"context"
"encoding/json"
"fmt"
"reflect"
"time"
"dario.cat/mergo"
opensearchgoAPI "github.com/opensearch-project/opensearch-go/v4/opensearchapi"
)
var (
@@ -65,26 +62,3 @@ func convert[T any](v any) (T, error) {
return t, nil
}
func clusterHealth(ctx context.Context, client *opensearchgoAPI.Client, indices []string) (*opensearchgoAPI.ClusterHealthResp, bool, error) {
resp, err := client.Cluster.Health(ctx, &opensearchgoAPI.ClusterHealthReq{
Indices: indices,
Params: opensearchgoAPI.ClusterHealthParams{
Local: opensearchgoAPI.ToPointer(true),
Timeout: 5 * time.Second,
},
})
if err != nil {
return nil, false, fmt.Errorf("%w, failed to get cluster health: %w", ErrUnhealthyCluster, err)
}
if resp.TimedOut {
return resp, false, fmt.Errorf("%w, cluster health request timed out", ErrUnhealthyCluster)
}
if resp.Status != "green" && resp.Status != "yellow" {
return resp, false, fmt.Errorf("%w, cluster health is not green or yellow: %s", ErrUnhealthyCluster, resp.Status)
}
return resp, true, nil
}

View File

@@ -85,3 +85,19 @@ func applyBuilders(target map[string]any, key string, bs ...Builder) error {
return nil
}
func builderToBoolQuery(b Builder) *BoolQuery {
var bq *BoolQuery
if q, ok := b.(*RootQuery); ok {
b = q.query
}
if q, ok := b.(*BoolQuery); !ok {
bq = NewBoolQuery().Must(b)
} else {
bq = q
}
return bq
}