|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// |
| 3 | +// The OpenSearch Contributors require contributions made to |
| 4 | +// this file be licensed under the Apache-2.0 license or a |
| 5 | +// compatible open source license. |
| 6 | + |
| 7 | +package ism |
| 8 | + |
| 9 | +import ( |
| 10 | + "context" |
| 11 | + "net/http" |
| 12 | + "strings" |
| 13 | + |
| 14 | + "github.com/opensearch-project/opensearch-go/v4" |
| 15 | +) |
| 16 | + |
| 17 | +// RefreshSearchAnalyzers executes a request to refresh search analyzers with the required RefreshSearchAnalyzersReq |
| 18 | +func (c Client) RefreshSearchAnalyzers(ctx context.Context, req RefreshSearchAnalyzersReq) (RefreshSearchAnalyzersResp, error) { |
| 19 | + var ( |
| 20 | + data RefreshSearchAnalyzersResp |
| 21 | + err error |
| 22 | + ) |
| 23 | + if data.response, err = c.do(ctx, req, &data); err != nil { |
| 24 | + return data, err |
| 25 | + } |
| 26 | + |
| 27 | + return data, nil |
| 28 | +} |
| 29 | + |
| 30 | +// RefreshSearchAnalyzersReq represents possible options for the /_plugins/_refresh_search_analyzers/<indices> request |
| 31 | +type RefreshSearchAnalyzersReq struct { |
| 32 | + Indices []string |
| 33 | + |
| 34 | + Header http.Header |
| 35 | + Params ReloadSearchAnalyzersParams |
| 36 | +} |
| 37 | + |
| 38 | +// GetRequest returns the *http.Request that gets executed by the client |
| 39 | +func (r RefreshSearchAnalyzersReq) GetRequest() (*http.Request, error) { |
| 40 | + indices := strings.Join(r.Indices, ",") |
| 41 | + |
| 42 | + var path strings.Builder |
| 43 | + path.Grow(len("/_plugins/_refresh_search_analyzers/") + len(indices)) |
| 44 | + path.WriteString("_plugins/_refresh_search_analyzers") |
| 45 | + if len(r.Indices) > 0 { |
| 46 | + path.WriteString("/") |
| 47 | + path.WriteString(indices) |
| 48 | + } |
| 49 | + |
| 50 | + return opensearch.BuildRequest( |
| 51 | + http.MethodPost, |
| 52 | + path.String(), |
| 53 | + nil, |
| 54 | + r.Params.get(), |
| 55 | + r.Header, |
| 56 | + ) |
| 57 | +} |
| 58 | + |
| 59 | +// RefreshSearchAnalyzersResp represents the returned struct of the refreshed search analyzers response |
| 60 | +type RefreshSearchAnalyzersResp struct { |
| 61 | + Shards RefreshSearchAnalyzersShards `json:"_shards"` |
| 62 | + SuccessfulRefreshDetails []RefreshSearchAnalyzersSuccessfulRefreshDetails `json:"successful_refresh_details"` |
| 63 | + response *opensearch.Response |
| 64 | +} |
| 65 | + |
| 66 | +// Inspect returns the Inspect type containing the raw *opensearch.Reponse |
| 67 | +func (r RefreshSearchAnalyzersResp) Inspect() Inspect { |
| 68 | + return Inspect{Response: r.response} |
| 69 | +} |
| 70 | + |
| 71 | +// RefreshSearchAnalyzersShards is a subtype of RefreshSearchAnalyzersResp representing information about the updated shards |
| 72 | +type RefreshSearchAnalyzersShards struct { |
| 73 | + Total int `json:"total"` |
| 74 | + Successful int `json:"successful"` |
| 75 | + Failed int `json:"failed"` |
| 76 | +} |
| 77 | + |
| 78 | +// RefreshSearchAnalyzersSuccessfulRefreshDetails is a subtype of RefreshSearchAnalyzersResp representing information about the analyzers |
| 79 | +type RefreshSearchAnalyzersSuccessfulRefreshDetails struct { |
| 80 | + Index string `json:"index"` |
| 81 | + RefreshedAnalyzers []string `json:"refreshed_analyzers"` |
| 82 | +} |
0 commit comments