mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 18:16:47 -05:00
enhancement(search): group opensearch related files together, housekeeping
This commit is contained in:
1 parent
5abfd1744e
commit
a7d4ff4872
14 files changed
+16
-26
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user