Skip to content

Commit ea1aef7

Browse files
authored
feat: (APIC-190) Add manage indices endpoints (#24)
1 parent 202e185 commit ea1aef7

File tree

17 files changed

+408
-9
lines changed

17 files changed

+408
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type DeleteIndexResponse = {
2+
/**
3+
* TaskID of the indexing task to wait for.
4+
*/
5+
taskID?: number;
6+
/**
7+
* Date of deletion (ISO-8601 format).
8+
*/
9+
deleteAt?: Date;
10+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export type Index = {
2+
/**
3+
* Index name.
4+
*/
5+
name: string;
6+
/**
7+
* Index creation date. An empty string means that the index has no records.
8+
*/
9+
createdAt: Date;
10+
/**
11+
* Date of last update (ISO-8601 format).
12+
*/
13+
updatedAt: Date;
14+
/**
15+
* Number of records contained in the index.
16+
*/
17+
entries: number;
18+
/**
19+
* Number of bytes of the index in minified format.
20+
*/
21+
dataSize: number;
22+
/**
23+
* Number of bytes of the index binary file.
24+
*/
25+
fileSize: number;
26+
/**
27+
* Last build time.
28+
*/
29+
lastBuildTimeS: number;
30+
/**
31+
* Number of pending indexing operations. This value is deprecated and should not be used.
32+
*/
33+
numberOfPendingTask?: number;
34+
/**
35+
* A boolean which says whether the index has pending tasks. This value is deprecated and should not be used.
36+
*/
37+
pendingTask: boolean;
38+
/**
39+
* Only present if the index is a replica. Contains the name of the related primary index.
40+
*/
41+
primary?: string;
42+
/**
43+
* Only present if the index is a primary index with replicas. Contains the names of all linked replicas.
44+
*/
45+
replicas?: string[];
46+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type ListIndicesObject = {
2+
/**
3+
* Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
4+
*/
5+
page?: number | null;
6+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Index } from './index';
2+
3+
export type ListIndicesResponse = {
4+
/**
5+
* List of the fetched indices.
6+
*/
7+
items?: Index[];
8+
/**
9+
* Number of pages.
10+
*/
11+
nbPages?: number;
12+
};

clients/algoliasearch-client-javascript/client-search/model/models.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ export * from './baseSearchResponse';
77
export * from './baseSearchResponseFacetsStats';
88
export * from './batchObject';
99
export * from './batchResponse';
10+
export * from './deleteIndexResponse';
1011
export * from './errorBase';
1112
export * from './highlightResult';
13+
export * from './index';
1214
export * from './indexSettings';
1315
export * from './indexSettingsAsSearchParams';
16+
export * from './listIndicesResponse';
1417
export * from './multipleQueries';
1518
export * from './multipleQueriesObject';
1619
export * from './multipleQueriesResponse';
1720
export * from './operation';
21+
export * from './operationIndexObject';
22+
export * from './operationIndexResponse';
1823
export * from './rankingInfo';
1924
export * from './rankingInfoMatchedGeoLocation';
2025
export * from './record';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export type OperationIndexObject = {
2+
/**
3+
* Type of operation to perform (move or copy).
4+
*/
5+
operation: OperationIndexObject.OperationEnum;
6+
/**
7+
* The Algolia index name.
8+
*/
9+
destination: string;
10+
/**
11+
* Scope of the data to copy. When absent, a full copy is performed. When present, only the selected scopes are copied.
12+
*/
13+
scope?: OperationIndexObject.ScopeEnum[];
14+
};
15+
16+
export namespace OperationIndexObject {
17+
export enum OperationEnum {
18+
Move = 'move',
19+
Copy = 'copy',
20+
}
21+
export enum ScopeEnum {
22+
Settings = 'settings',
23+
Synonyms = 'synonyms',
24+
Rules = 'rules',
25+
}
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type OperationIndexResponse = {
2+
/**
3+
* TaskID of the indexing task to wait for.
4+
*/
5+
taskID?: number;
6+
/**
7+
* Date of last update (ISO-8601 format).
8+
*/
9+
updatedAt?: Date;
10+
};

clients/algoliasearch-client-javascript/client-search/src/searchApi.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import type { BatchObject } from '../model/batchObject';
22
import type { BatchResponse } from '../model/batchResponse';
3+
import type { DeleteIndexResponse } from '../model/deleteIndexResponse';
34
import type { IndexSettings } from '../model/indexSettings';
5+
import type { ListIndicesResponse } from '../model/listIndicesResponse';
46
import { ApiKeyAuth } from '../model/models';
57
import type { MultipleQueriesObject } from '../model/multipleQueriesObject';
68
import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse';
9+
import type { OperationIndexObject } from '../model/operationIndexObject';
10+
import type { OperationIndexResponse } from '../model/operationIndexResponse';
711
import type { SaveObjectResponse } from '../model/saveObjectResponse';
812
import type { SearchParams } from '../model/searchParams';
913
import type { SearchParamsAsString } from '../model/searchParamsAsString';
@@ -142,6 +146,38 @@ export class SearchApi {
142146

143147
return this.sendRequest(request, requestOptions);
144148
}
149+
/**
150+
* Delete an existing index.
151+
*
152+
* @summary Delete index.
153+
* @param indexName - The index in which to perform the request.
154+
*/
155+
deleteIndex(indexName: string): Promise<DeleteIndexResponse> {
156+
const path = '/1/indexes/{indexName}'.replace(
157+
'{indexName}',
158+
encodeURIComponent(String(indexName))
159+
);
160+
const headers: Headers = { Accept: 'application/json' };
161+
const queryParameters: Record<string, string> = {};
162+
163+
if (indexName === null || indexName === undefined) {
164+
throw new Error(
165+
'Required parameter indexName was null or undefined when calling deleteIndex.'
166+
);
167+
}
168+
169+
const request: Request = {
170+
method: 'DELETE',
171+
path,
172+
};
173+
174+
const requestOptions: RequestOptions = {
175+
headers,
176+
queryParameters,
177+
};
178+
179+
return this.sendRequest(request, requestOptions);
180+
}
145181
/**
146182
* Retrieve settings of a given indexName.
147183
*
@@ -173,6 +209,33 @@ export class SearchApi {
173209

174210
return this.sendRequest(request, requestOptions);
175211
}
212+
/**
213+
* List existing indexes from an application.
214+
*
215+
* @summary List existing indexes.
216+
* @param page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
217+
*/
218+
listIndices(page?: number): Promise<ListIndicesResponse> {
219+
const path = '/1/indexes';
220+
const headers: Headers = { Accept: 'application/json' };
221+
const queryParameters: Record<string, string> = {};
222+
223+
if (page !== undefined) {
224+
queryParameters.Page = page.toString();
225+
}
226+
227+
const request: Request = {
228+
method: 'GET',
229+
path,
230+
};
231+
232+
const requestOptions: RequestOptions = {
233+
headers,
234+
queryParameters,
235+
};
236+
237+
return this.sendRequest(request, requestOptions);
238+
}
176239
/**
177240
* Get search results for the given requests.
178241
*
@@ -204,6 +267,49 @@ export class SearchApi {
204267

205268
return this.sendRequest(request, requestOptions);
206269
}
270+
/**
271+
* Peforms a copy or a move operation on a index.
272+
*
273+
* @summary Copy/move index.
274+
* @param indexName - The index in which to perform the request.
275+
* @param operationIndexObject - The operationIndexObject.
276+
*/
277+
operationIndex(
278+
indexName: string,
279+
operationIndexObject: OperationIndexObject
280+
): Promise<OperationIndexResponse> {
281+
const path = '/1/indexes/{indexName}/operation'.replace(
282+
'{indexName}',
283+
encodeURIComponent(String(indexName))
284+
);
285+
const headers: Headers = { Accept: 'application/json' };
286+
const queryParameters: Record<string, string> = {};
287+
288+
if (indexName === null || indexName === undefined) {
289+
throw new Error(
290+
'Required parameter indexName was null or undefined when calling operationIndex.'
291+
);
292+
}
293+
294+
if (operationIndexObject === null || operationIndexObject === undefined) {
295+
throw new Error(
296+
'Required parameter operationIndexObject was null or undefined when calling operationIndex.'
297+
);
298+
}
299+
300+
const request: Request = {
301+
method: 'POST',
302+
path,
303+
data: operationIndexObject,
304+
};
305+
306+
const requestOptions: RequestOptions = {
307+
headers,
308+
queryParameters,
309+
};
310+
311+
return this.sendRequest(request, requestOptions);
312+
}
207313
/**
208314
* Add an object to the index, automatically assigning it an object ID.
209315
*

specs/common/parameters.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ ForwardToReplicas:
1616
schema:
1717
type: boolean
1818

19+
# query
20+
Page:
21+
in: query
22+
name: Page
23+
description: Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
24+
schema:
25+
type: integer
26+
nullable: true
27+
default: null
28+
1929
# misc
2030
taskID:
2131
type: integer
@@ -49,6 +59,11 @@ updatedAt:
4959
format: date-time
5060
description: Date of last update (ISO-8601 format).
5161

62+
deleteAt:
63+
type: string
64+
format: date-time
65+
description: Date of deletion (ISO-8601 format).
66+
5267
indexName:
5368
type: string
5469
example: products
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
listIndicesResponse:
2+
type: object
3+
additionalProperties: false
4+
properties:
5+
items:
6+
type: array
7+
description: List of the fetched indices.
8+
items:
9+
$ref: '#/index'
10+
nbPages:
11+
type: integer
12+
description: Number of pages.
13+
example: 100
14+
15+
index:
16+
type: object
17+
additionalProperties: false
18+
properties:
19+
name:
20+
type: string
21+
description: Index name.
22+
createdAt:
23+
type: string
24+
format: date-time
25+
description: Index creation date. An empty string means that the index has no records.
26+
updatedAt:
27+
$ref: '../../../common/parameters.yml#/updatedAt'
28+
entries:
29+
type: integer
30+
description: Number of records contained in the index.
31+
dataSize:
32+
type: integer
33+
description: Number of bytes of the index in minified format.
34+
fileSize:
35+
type: integer
36+
description: Number of bytes of the index binary file.
37+
lastBuildTimeS:
38+
type: integer
39+
description: Last build time
40+
numberOfPendingTask:
41+
type: integer
42+
description: Number of pending indexing operations. This value is deprecated and should not be used.
43+
pendingTask:
44+
type: boolean
45+
description: A boolean which says whether the index has pending tasks. This value is deprecated and should not be used.
46+
primary:
47+
type: string
48+
description: Only present if the index is a replica. Contains the name of the related primary index.
49+
replicas:
50+
type: array
51+
items:
52+
type: string
53+
description: Only present if the index is a primary index with replicas. Contains the names of all linked replicas.
54+
required:
55+
- name
56+
- createdAt
57+
- updatedAt
58+
- entries
59+
- dataSize
60+
- fileSize
61+
- lastBuildTimeS
62+
- pendingTask

specs/search/paths/manage_indices/copyIndex.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
get:
2+
tags:
3+
- search
4+
operationId: listIndices
5+
summary: List existing indexes.
6+
description: List existing indexes from an application.
7+
parameters:
8+
- $ref: '../../../common/parameters.yml#/Page'
9+
responses:
10+
'200':
11+
description: OK
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '../../common/schemas/listIndicesResponse.yml#/listIndicesResponse'
16+
'400':
17+
$ref: '../../../common/responses/BadRequest.yml'
18+
'402':
19+
$ref: '../../../common/responses/FeatureNotEnabled.yml'
20+
'403':
21+
$ref: '../../../common/responses/MethodNotAllowed.yml'
22+
'404':
23+
$ref: '../../../common/responses/IndexNotFound.yml'

0 commit comments

Comments
 (0)