Skip to content

Commit

Permalink
Fix deprecations and missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
olivere committed Mar 19, 2022
1 parent fa42b0c commit 751f1dc
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 286 deletions.
14 changes: 14 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1694,11 +1694,17 @@ func (c *Client) CloseIndex(name string) *IndicesCloseService {
}

// FreezeIndex freezes an index.
//
// Deprecated: Frozen indices are deprecated because they provide no benefit
// given improvements in heap memory utilization.
func (c *Client) FreezeIndex(name string) *IndicesFreezeService {
return NewIndicesFreezeService(c).Index(name)
}

// UnfreezeIndex unfreezes an index.
//
// Deprecated: Frozen indices are deprecated because they provide no benefit
// given improvements in heap memory utilization.
func (c *Client) UnfreezeIndex(name string) *IndicesUnfreezeService {
return NewIndicesUnfreezeService(c).Index(name)
}
Expand Down Expand Up @@ -1779,6 +1785,8 @@ func (c *Client) Aliases() *AliasesService {
// in https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-templates-v1.html.
//
// See e.g. IndexPutIndexTemplate and IndexPutComponentTemplate for the new version(s).
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
func (c *Client) IndexGetTemplate(names ...string) *IndicesGetTemplateService {
return NewIndicesGetTemplateService(c).Name(names...)
}
Expand All @@ -1789,6 +1797,8 @@ func (c *Client) IndexGetTemplate(names ...string) *IndicesGetTemplateService {
// in https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-templates-v1.html.
//
// See e.g. IndexPutIndexTemplate and IndexPutComponentTemplate for the new version(s).
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
func (c *Client) IndexTemplateExists(name string) *IndicesExistsTemplateService {
return NewIndicesExistsTemplateService(c).Name(name)
}
Expand All @@ -1799,6 +1809,8 @@ func (c *Client) IndexTemplateExists(name string) *IndicesExistsTemplateService
// in https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-templates-v1.html.
//
// See e.g. IndexPutIndexTemplate and IndexPutComponentTemplate for the new version(s).
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
func (c *Client) IndexPutTemplate(name string) *IndicesPutTemplateService {
return NewIndicesPutTemplateService(c).Name(name)
}
Expand All @@ -1809,6 +1821,8 @@ func (c *Client) IndexPutTemplate(name string) *IndicesPutTemplateService {
// in https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-templates-v1.html.
//
// See e.g. IndexPutIndexTemplate and IndexPutComponentTemplate for the new version(s).
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
func (c *Client) IndexDeleteTemplate(name string) *IndicesDeleteTemplateService {
return NewIndicesDeleteTemplateService(c).Name(name)
}
Expand Down
50 changes: 35 additions & 15 deletions cluster_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,19 @@ func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, er

// ClusterStateResponse is the response of ClusterStateService.Do.
type ClusterStateResponse struct {
ClusterName string `json:"cluster_name"`
ClusterUUID string `json:"cluster_uuid"`
Version int64 `json:"version"`
StateUUID string `json:"state_uuid"`
MasterNode string `json:"master_node"`
Blocks map[string]*clusterBlocks `json:"blocks"`
Nodes map[string]*discoveryNode `json:"nodes"`
Metadata *clusterStateMetadata `json:"metadata"`
RoutingTable *clusterStateRoutingTable `json:"routing_table"`
RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"`
Customs map[string]interface{} `json:"customs"`
ClusterName string `json:"cluster_name"`
ClusterUUID string `json:"cluster_uuid"`
Version int64 `json:"version"`
StateUUID string `json:"state_uuid"`
MasterNode string `json:"master_node"`
Blocks map[string]*clusterBlocks `json:"blocks"`
Nodes map[string]*discoveryNode `json:"nodes"`
Metadata *clusterStateMetadata `json:"metadata"`
RoutingTable *clusterStateRoutingTable `json:"routing_table"`
RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"`
Snapshots map[string]interface{} `json:"snapshots"`
SnapshotDeletions map[string]interface{} `json:"snapshot_deletions"`
Customs map[string]interface{} `json:"customs"`
}

type clusterBlocks struct {
Expand Down Expand Up @@ -273,10 +275,16 @@ type clusterStateMetadata struct {
Unassigned []*shardRouting `json:"unassigned"`
Nodes []*shardRouting `json:"nodes"`
} `json:"routing_nodes"`
Customs map[string]interface{} `json:"customs"`
Ingest map[string]interface{} `json:"ingest"`
StoredScripts map[string]interface{} `json:"stored_scripts"`
IndexGraveyard map[string]interface{} `json:"index-graveyard"`
DataStream map[string]interface{} `json:"data_stream,omitempty"`
Customs map[string]interface{} `json:"customs"`
Ingest map[string]interface{} `json:"ingest"`
StoredScripts map[string]interface{} `json:"stored_scripts"`
IndexGraveyard map[string]interface{} `json:"index-graveyard"`
IndexLifecycle map[string]interface{} `json:"index_lifecycle"`
Repositories map[string]interface{} `json:"repositories"`
IndexTemplate map[string]interface{} `json:"index_template"`
PersistentTasks map[string]interface{} `json:"persistent_tasks"`
ComponentTemplate map[string]interface{} `json:"component_template"`
}

type clusterCoordinationMetaData struct {
Expand All @@ -291,6 +299,7 @@ type discoveryNode struct {
EphemeralID string `json:"ephemeral_id"` // e.g. "paHSLpn6QyuVy_n-GM1JAQ"
TransportAddress string `json:"transport_address"` // e.g. inet[/1.2.3.4:9300]
Attributes map[string]interface{} `json:"attributes"` // e.g. { "data": true, "master": true }
Roles []string `json:"roles,omitempty"` // e.g. ["data","data_cold","master",...]
}

type clusterStateRoutingTable struct {
Expand All @@ -306,8 +315,10 @@ type clusterStateRoutingNode struct {
type indexTemplateMetaData struct {
IndexPatterns []string `json:"index_patterns"` // e.g. ["store-*"]
Order int `json:"order"`
Version int `json:"version"`
Settings map[string]interface{} `json:"settings"` // index settings
Mappings map[string]interface{} `json:"mappings"` // type name -> mapping
Aliases map[string]interface{} `json:"aliases"`
}

type indexMetaData struct {
Expand All @@ -317,6 +328,15 @@ type indexMetaData struct {
Aliases []string `json:"aliases"` // e.g. [ "alias1", "alias2" ]
PrimaryTerms map[string]interface{} `json:"primary_terms"`
InSyncAllocations map[string]interface{} `json:"in_sync_allocations"`
Version int `json:"version"`
MappingVersion int `json:"mapping_version"`
SettingsVersion int `json:"settings_version"`
AliasesVersion int `json:"aliases_version"`
RoutingNumShards int `json:"routing_num_shards"`
RolloverInfo interface{} `json:"rollover_info,omitempty"`
System interface{} `json:"system,omitempty"`
TimestampRange interface{} `json:"timestamp_range,omitempty"`
ILM map[string]interface{} `json:"ilm,omitempty"`
}

type indexRoutingTable struct {
Expand Down
2 changes: 1 addition & 1 deletion cluster_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestClusterStateURLs(t *testing.T) {
}

func TestClusterStateGet(t *testing.T) {
client := setupTestClientAndCreateIndex(t) // , SetTraceLog(log.New(os.Stdout, "", 0)))
client := setupTestClientAndCreateIndex(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))

state, err := client.ClusterState().Pretty(true).Do(context.TODO())
if err != nil {
Expand Down
106 changes: 98 additions & 8 deletions cluster_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,72 @@ type ClusterStatsIndices struct {
QueryCache *ClusterStatsIndicesQueryCache `json:"query_cache"`
Completion *ClusterStatsIndicesCompletion `json:"completion"`
Segments *IndexStatsSegments `json:"segments"`
Analysis *ClusterStatsAnalysisStats `json:"analysis"`
Mappings *ClusterStatsMappingStats `json:"mappings"`
Versions []*ClusterStatsVersionStats `json:"versions"`
}

type ClusterStatsAnalysisStats struct {
CharFilterTypes []IndexFeatureStats `json:"char_filter_types,omitempty"`
TokenizerTypes []IndexFeatureStats `json:"tokenizer_types,omitempty"`
FilterTypes []IndexFeatureStats `json:"filter_types,omitempty"`
AnalyzerTypes []IndexFeatureStats `json:"analyzer_types,omitempty"`
BuiltInCharFilters []IndexFeatureStats `json:"built_in_char_filters,omitempty"`
BuiltInTokenizers []IndexFeatureStats `json:"built_in_tokenizers,omitempty"`
BuiltInFilters []IndexFeatureStats `json:"built_in_filters,omitempty"`
BuiltInAnalyzers []IndexFeatureStats `json:"built_in_analyzers,omitempty"`
}

type ClusterStatsMappingStats struct {
FieldTypes []IndexFeatureStats `json:"field_types"`
RuntimeFieldTypes []RuntimeFieldStats `json:"runtime_field_types"`
}

type IndexFeatureStats struct {
Name string `json:"name"`
Count int `json:"count"`
IndexCount int `json:"index_count"`

ScriptCount int `json:"script_count"`
}

type RuntimeFieldStats struct {
Name string `json:"name"`
Count int `json:"count"`
IndexCount int `json:"index_count"`
ScriptlessCount int `json:"scriptless_count"`
ShadowedCount int `json:"shadowed_count"`
Lang []string `json:"lang"`

// FieldScriptStats

LinesMax int64 `json:"lines_max"`
LinesTotal int64 `json:"lines_total"`
CharsMax int64 `json:"chars_max"`
CharsTotal int64 `json:"chars_total"`
SourceMax int64 `json:"source_max"`
SourceTotal int64 `json:"source_total"`
DocMax int64 `json:"doc_max"`
DocTotal int64 `json:"doc_total"`
}

type FieldScriptStats struct {
LinesMax int64 `json:"lines_max"`
LinesTotal int64 `json:"lines_total"`
CharsMax int64 `json:"chars_max"`
CharsTotal int64 `json:"chars_total"`
SourceMax int64 `json:"source_max"`
SourceTotal int64 `json:"source_total"`
DocMax int64 `json:"doc_max"`
DocTotal int64 `json:"doc_total"`
}

type ClusterStatsVersionStats struct {
Version string `json:"version"`
IndexCount int `json:"index_count"`
PrimaryShardCount int `json:"primary_shard_count"`
TotalPrimarySize string `json:"total_primary_size,omitempty"`
TotalPrimaryBytes int64 `json:"total_primary_bytes,omitempty"`
}

type ClusterStatsIndicesShards struct {
Expand Down Expand Up @@ -226,8 +292,12 @@ type ClusterStatsIndicesDocs struct {
}

type ClusterStatsIndicesStore struct {
Size string `json:"size"` // e.g. "5.3gb"
SizeInBytes int64 `json:"size_in_bytes"`
Size string `json:"size"` // e.g. "5.3gb"
SizeInBytes int64 `json:"size_in_bytes"`
TotalDataSetSize string `json:"total_data_set_size,omitempty"`
TotalDataSetSizeInBytes int64 `json:"total_data_set_size_in_bytes,omitempty"`
Reserved string `json:"reserved,omitempty"`
ReservedInBytes int64 `json:"reserved_in_bytes,omitempty"`
}

type ClusterStatsIndicesFieldData struct {
Expand Down Expand Up @@ -280,14 +350,25 @@ type ClusterStatsNodes struct {
NetworkTypes *ClusterStatsNodesNetworkTypes `json:"network_types"`
DiscoveryTypes *ClusterStatsNodesDiscoveryTypes `json:"discovery_types"`
PackagingTypes *ClusterStatsNodesPackagingTypes `json:"packaging_types"`

Ingest *ClusterStatsNodesIngest `json:"ingest"`
}

type ClusterStatsNodesCount struct {
Total int `json:"total"`
Data int `json:"data"`
CoordinatingOnly int `json:"coordinating_only"`
Master int `json:"master"`
Ingest int `json:"ingest"`
Total int `json:"total"`
Data int `json:"data"`
DataCold int `json:"data_cold"`
DataContent int `json:"data_content"`
DataFrozen int `json:"data_frozen"`
DataHot int `json:"data_hot"`
DataWarm int `json:"data_warm"`
CoordinatingOnly int `json:"coordinating_only"`
Master int `json:"master"`
Ingest int `json:"ingest"`
ML int `json:"ml"`
RemoteClusterClient int `json:"remote_cluster_client"`
Transform int `json:"transform"`
VotingOnly int `json:"voting_only"`
}

type ClusterStatsNodesOsStats struct {
Expand All @@ -301,7 +382,11 @@ type ClusterStatsNodesOsStats struct {
PrettyName string `json:"pretty_name"`
Value int `json:"count"`
} `json:"pretty_names"`
Mem *ClusterStatsNodesOsStatsMem `json:"mem"`
Mem *ClusterStatsNodesOsStatsMem `json:"mem"`
Architectures []struct {
Arch string `json:"arch"`
Count int `json:"count"`
} `json:"architectures"`
// CPU []*ClusterStatsNodesOsStatsCPU `json:"cpu"`
}

Expand Down Expand Up @@ -414,3 +499,8 @@ type ClusterStatsNodesPackagingType struct {
Type string `json:"type"` // e.g. "docker"
Count int `json:"count"` // e.g. 1
}

type ClusterStatsNodesIngest struct {
NumberOfPipelines int `json:"number_of_pipelines"`
ProcessorStats map[string]interface{} `json:"processor_stats"`
}
2 changes: 1 addition & 1 deletion cluster_stats_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestClusterStats(t *testing.T) {
client := setupTestClientAndCreateIndexAndAddDocs(t) // , SetTraceLog(log.New(os.Stdout, "", 0)))
client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))

// Get cluster stats
res, err := client.ClusterStats().Human(true).Pretty(true).Do(context.Background())
Expand Down
52 changes: 0 additions & 52 deletions count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,55 +115,3 @@ func TestCount(t *testing.T) {
t.Errorf("expected Count = %d; got %d", 2, count)
}
}

func TestCountWithThrottledIndex(t *testing.T) {
client := setupTestClient(t, SetURL("http://elastic:elastic@localhost:9210"))

tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}

// Add all documents
_, err := client.Index().Index(testIndexName).Id("1").BodyJson(&tweet1).Do(context.TODO())
if err != nil {
t.Fatal(err)
}

_, err = client.Index().Index(testIndexName).Id("2").BodyJson(&tweet2).Do(context.TODO())
if err != nil {
t.Fatal(err)
}

_, err = client.Index().Index(testIndexName).Id("3").BodyJson(&tweet3).Do(context.TODO())
if err != nil {
t.Fatal(err)
}

_, err = client.FreezeIndex(testIndexName).Do(context.TODO())
if err != nil {
t.Fatal(err)
}

_, err = client.Refresh().Index(testIndexName).Do(context.TODO())
if err != nil {
t.Fatal(err)
}

// Count documents
count, err := client.Count(testIndexName).Do(context.TODO())
if err != nil {
t.Fatal(err)
}
if count != 0 {
t.Errorf("expected Count = %d; got %d", 3, count)
}

// Count documents
count, err = client.Count(testIndexName).IgnoreThrottled(false).Do(context.TODO())
if err != nil {
t.Fatal(err)
}
if count != 3 {
t.Errorf("expected Count = %d; got %d", 3, count)
}
}
8 changes: 8 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ type ShardOperationFailedException struct {
Primary bool `json:"primary,omitempty"`
}

type BroadcastResponse struct {
Shards *ShardsInfo `json:"_shards,omitempty"`
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
Failures []*ShardOperationFailedException `json:"failures,omitempty"`
}

// FailedNodeException returns an error on the node level.
type FailedNodeException struct {
*ErrorDetails
Expand Down
4 changes: 4 additions & 0 deletions indices_delete_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-delete-template-v1.html
// for more details.
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
type IndicesDeleteTemplateService struct {
client *Client

Expand Down Expand Up @@ -147,6 +149,8 @@ func (s *IndicesDeleteTemplateService) Validate() error {
}

// Do executes the operation.
//
// Deprecated: Legacy index templates are deprecated in favor of composable templates.
func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTemplateResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
Expand Down
Loading

0 comments on commit 751f1dc

Please sign in to comment.