(ctx context.Context)
| 203 | } |
| 204 | |
| 205 | func (d *Driver) getIndices(ctx context.Context) ([]*storepb.TableMetadata, error) { |
| 206 | var indicesMetadata []*storepb.TableMetadata |
| 207 | |
| 208 | // Get hidden indices to filter them out. |
| 209 | hiddenIndices, err := d.getHiddenIndices(ctx) |
| 210 | if err != nil { |
| 211 | return nil, errors.Wrap(err, "failed to get hidden indices") |
| 212 | } |
| 213 | |
| 214 | if d.isOpenSearch && d.opensearchAPI != nil { |
| 215 | resp, err := d.opensearchAPI.Cat.Indices(ctx, &opensearchapi.CatIndicesReq{}) |
| 216 | if err != nil { |
| 217 | return nil, errors.Wrapf(err, "failed to list indices") |
| 218 | } |
| 219 | |
| 220 | for _, idx := range resp.Indices { |
| 221 | if hiddenIndices[idx.Index] { |
| 222 | continue |
| 223 | } |
| 224 | |
| 225 | var datasize int64 |
| 226 | if idx.StoreSize != nil { |
| 227 | datasize, err = unitConversion(*idx.StoreSize) |
| 228 | if err != nil { |
| 229 | return nil, err |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | var docCount int64 |
| 234 | if idx.DocsCount != nil { |
| 235 | docCount = int64(*idx.DocsCount) |
| 236 | } |
| 237 | |
| 238 | indicesMetadata = append(indicesMetadata, &storepb.TableMetadata{ |
| 239 | Name: idx.Index, |
| 240 | DataSize: datasize, |
| 241 | RowCount: docCount, |
| 242 | }) |
| 243 | } |
| 244 | |
| 245 | return indicesMetadata, nil |
| 246 | } else if d.typedClient != nil { |
| 247 | res, err := esapi.CatIndicesRequest{Format: "json", Pretty: true}.Do(ctx, d.typedClient) |
| 248 | if err != nil { |
| 249 | return nil, errors.Wrapf(err, "failed to list indices") |
| 250 | } |
| 251 | |
| 252 | bytes, err := readBytesAndClose(res) |
| 253 | if err != nil { |
| 254 | return nil, errors.Wrap(err, "failed to list Elasticsearch indices") |
| 255 | } |
| 256 | |
| 257 | var results []IndicesResult |
| 258 | if err := json.Unmarshal(bytes, &results); err != nil { |
| 259 | // Include response body to help debug parsing issues |
| 260 | bodyPreview, truncated := common.TruncateString(string(bytes), 500) |
| 261 | if truncated { |
| 262 | bodyPreview += "..." |
no test coverage detected