go.temporal.io/server@v1.23.0/common/persistence/visibility/store/elasticsearch/client/client.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 //go:generate mockgen -copyright_file ../../../../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination client_mock.go 26 27 package client 28 29 import ( 30 "context" 31 "time" 32 33 "github.com/olivere/elastic/v7" 34 enumspb "go.temporal.io/api/enums/v1" 35 ) 36 37 const ( 38 versionTypeExternal = "external" 39 minimumCloseIdleConnectionsInterval = 15 * time.Second 40 ) 41 42 type ( 43 // Client is a wrapper around Elasticsearch client library. 44 Client interface { 45 Get(ctx context.Context, index string, docID string) (*elastic.GetResult, error) 46 Search(ctx context.Context, p *SearchParameters) (*elastic.SearchResult, error) 47 Count(ctx context.Context, index string, query elastic.Query) (int64, error) 48 CountGroupBy(ctx context.Context, index string, query elastic.Query, aggName string, agg elastic.Aggregation) (*elastic.SearchResult, error) 49 RunBulkProcessor(ctx context.Context, p *BulkProcessorParameters) (BulkProcessor, error) 50 51 // TODO (alex): move this to some admin client (and join with IntegrationTestsClient) 52 PutMapping(ctx context.Context, index string, mapping map[string]enumspb.IndexedValueType) (bool, error) 53 WaitForYellowStatus(ctx context.Context, index string) (string, error) 54 GetMapping(ctx context.Context, index string) (map[string]string, error) 55 56 OpenScroll(ctx context.Context, p *SearchParameters, keepAliveInterval string) (*elastic.SearchResult, error) 57 Scroll(ctx context.Context, id string, keepAliveInterval string) (*elastic.SearchResult, error) 58 CloseScroll(ctx context.Context, id string) error 59 60 IsPointInTimeSupported(ctx context.Context) bool 61 OpenPointInTime(ctx context.Context, index string, keepAliveInterval string) (string, error) 62 ClosePointInTime(ctx context.Context, id string) (bool, error) 63 } 64 65 CLIClient interface { 66 Client 67 Delete(ctx context.Context, indexName string, docID string, version int64) error 68 } 69 70 IntegrationTestsClient interface { 71 CreateIndex(ctx context.Context, index string) (bool, error) 72 IndexPutTemplate(ctx context.Context, templateName string, bodyString string) (bool, error) 73 IndexExists(ctx context.Context, indexName string) (bool, error) 74 DeleteIndex(ctx context.Context, indexName string) (bool, error) 75 IndexPutSettings(ctx context.Context, indexName string, bodyString string) (bool, error) 76 IndexGetSettings(ctx context.Context, indexName string) (map[string]*elastic.IndicesGetSettingsResponse, error) 77 PutMapping(ctx context.Context, index string, mapping map[string]enumspb.IndexedValueType) (bool, error) 78 Ping(ctx context.Context) error 79 } 80 81 // SearchParameters holds all required and optional parameters for executing a search. 82 SearchParameters struct { 83 Index string 84 Query elastic.Query 85 PageSize int 86 Sorter []elastic.Sorter 87 88 SearchAfter []interface{} 89 ScrollID string 90 PointInTime *elastic.PointInTime 91 } 92 )