Browse Source

Fix SearchShards API

This commit fixes a serialization issue with SearchShards API (see #897).

Furthermore, it completes the structures related to the response of that
API.

Close #902
tags/v6.2.6
Oliver Eilhard 1 year ago
parent
commit
e7465c050f
2 changed files with 34 additions and 11 deletions
  1. 30
    7
      search_shards.go
  2. 4
    4
      search_shards_test.go

+ 30
- 7
search_shards.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"fmt"
10 10
 	"net/url"
11 11
 	"strings"
12
+	"time"
12 13
 
13 14
 	"github.com/olivere/elastic/uritemplates"
14 15
 )
@@ -174,11 +175,33 @@ type SearchShardsResponse struct {
174 175
 }
175 176
 
176 177
 type ShardsInfo struct {
177
-	Index          string      `json:"index"`
178
-	Node           string      `json:"node"`
179
-	Primary        bool        `json:"primary"`
180
-	Shard          uint        `json:"shard"`
181
-	State          string      `json:"state"`
182
-	AllocationId   interface{} `json:"allocation_id"`
183
-	RelocatingNode bool        `json:"relocating_node"`
178
+	Index                    string          `json:"index"`
179
+	Node                     string          `json:"node"`
180
+	Primary                  bool            `json:"primary"`
181
+	Shard                    uint            `json:"shard"`
182
+	State                    string          `json:"state"`
183
+	AllocationId             *AllocationId   `json:"allocation_id,omitempty"`
184
+	RelocatingNode           string          `json:"relocating_node"`
185
+	ExpectedShardSizeInBytes int64           `json:"expected_shard_size_in_bytes,omitempty"`
186
+	RecoverySource           *RecoverySource `json:"recovery_source,omitempty"`
187
+	UnassignedInfo           *UnassignedInfo `json:"unassigned_info,omitempty"`
188
+}
189
+
190
+type RecoverySource struct {
191
+	Type string `json:"type"`
192
+	// TODO add missing fields here based on the Type
193
+}
194
+
195
+type AllocationId struct {
196
+	Id           string `json:"id"`
197
+	RelocationId string `json:"relocation_id,omitempty"`
198
+}
199
+
200
+type UnassignedInfo struct {
201
+	Reason           string     `json:"reason"`
202
+	At               *time.Time `json:"at,omitempty"`
203
+	FailedAttempts   int        `json:"failed_attempts,omitempty"`
204
+	Delayed          bool       `json:"delayed"`
205
+	Details          string     `json:"details,omitempty"`
206
+	AllocationStatus string     `json:"allocation_status"`
184 207
 }

+ 4
- 4
search_shards_test.go View File

@@ -10,11 +10,13 @@ import (
10 10
 )
11 11
 
12 12
 func TestSearchShards(t *testing.T) {
13
-	client := setupTestClientAndCreateIndex(t)
13
+	client := setupTestClientAndCreateIndex(t) //, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))
14 14
 
15 15
 	indexes := []string{testIndexName}
16 16
 
17
-	shardsInfo, err := client.SearchShards(indexes...).Do(context.TODO())
17
+	shardsInfo, err := client.SearchShards(indexes...).
18
+		Pretty(true).
19
+		Do(context.Background())
18 20
 	if err != nil {
19 21
 		t.Fatal(err)
20 22
 	}
@@ -24,11 +26,9 @@ func TestSearchShards(t *testing.T) {
24 26
 	if len(shardsInfo.Shards) < 1 {
25 27
 		t.Fatal("expected to return minimun one shard information")
26 28
 	}
27
-
28 29
 	if shardsInfo.Shards[0][0].Index != testIndexName {
29 30
 		t.Fatal("expected to return shard info concerning requested index")
30 31
 	}
31
-
32 32
 	if shardsInfo.Shards[0][0].State != "STARTED" {
33 33
 		t.Fatal("expected to return STARTED status for running shards")
34 34
 	}

Loading…
Cancel
Save