Skip to content

Commit dc54c8e

Browse files
support creating index on update if missing (#5773)
* add support for creating missing index on update * add create-on-update to cli * add test * optionally create source on update * add documentation
1 parent 0bb7809 commit dc54c8e

File tree

15 files changed

+451
-33
lines changed

15 files changed

+451
-33
lines changed

docs/reference/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ quickwit index update
199199
|-----------------|-------------|
200200
| `--index` | ID of the target index |
201201
| `--index-config` | Location of the index config file. |
202+
| `--create` | Create the index if it doesn't exist. |
202203
### index clear
203204

204205
Clears an index: deletes all splits and resets checkpoint.
@@ -514,6 +515,7 @@ quickwit source update
514515
| `--index` | ID of the target index |
515516
| `--source` | ID of the source |
516517
| `--source-config` | Path to source config file. Please, refer to the documentation for more details. |
518+
| `--create` | Create the source if it doesn't exist. |
517519
### source enable
518520

519521
Enables a source for an index.

docs/reference/rest-api.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,19 @@ The response is the index metadata of the created index, and the content type is
327327
PUT api/v1/indexes/<index id>
328328
```
329329

330-
Updates the configurations of an index. This endpoint follows PUT semantics, which means that all the fields of the current configuration are replaced by the values specified in this request or the associated defaults. In particular, if the field is optional (e.g. `retention_policy`), omitting it will delete the associated configuration. If the new configuration file contains updates that cannot be applied, the request fails, and none of the updates are applied. The API accepts JSON with `content-type: application/json` and YAML with `content-type: application/yaml`.
330+
#### Path variable
331+
332+
| Variable | Description |
333+
| ------------- | ------------- |
334+
| `index id` | The index id |
335+
336+
#### Query parameters
337+
338+
| Variable | Type | Description | Default value |
339+
|-----------|--------|-----------------------------------------------|---------------|
340+
| `create` | `bool` | Create the index if it doesn't already exists | `false` |
341+
342+
Update the configurations of an index. This endpoint follows PUT semantics, which means that all the fields of the current configuration are replaced by the values specified in this request or the associated defaults. In particular, if the field is optional (e.g. `retention_policy`), omitting it will delete the associated configuration. If the new configuration file contains updates that cannot be applied, the request fails, and none of the updates are applied. The API accepts JSON with `content-type: application/json` and YAML with `content-type: application/yaml`.
331343

332344
- The retention policy update is automatically picked up by the janitor service on its next state refresh.
333345
- The search settings update is automatically picked up by searcher nodes when the next query is executed.
@@ -645,6 +657,19 @@ The response is the created source config, and the content type is `application/
645657
PUT api/v1/indexes/<index id>/sources/<source id>
646658
```
647659

660+
#### Path variable
661+
662+
| Variable | Description |
663+
| ------------- | ------------- |
664+
| `index id` | The index id |
665+
| `source id` | The source id |
666+
667+
#### Query parameters
668+
669+
| Variable | Type | Description | Default value |
670+
|-----------|--------|-----------------------------------------------|---------------|
671+
| `create` | `bool` | Create the index if it doesn't already exists | `false` |
672+
648673
Update a source by posting a source config JSON payload.
649674

650675
#### PUT payload

quickwit/quickwit-cli/src/index.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub fn build_index_command() -> Command {
7676
arg!(--"index-config" <INDEX_CONFIG> "Location of the index config file.")
7777
.display_order(2)
7878
.required(true),
79+
arg!(--"create" "Create the index if it does not already exists.")
80+
.display_order(3)
81+
.required(false),
7982
])
8083
)
8184
.subcommand(
@@ -212,6 +215,7 @@ pub struct UpdateIndexArgs {
212215
pub client_args: ClientArgs,
213216
pub index_id: IndexId,
214217
pub index_config_uri: Uri,
218+
pub create: bool,
215219
pub assume_yes: bool,
216220
}
217221

@@ -335,12 +339,14 @@ impl IndexCliCommand {
335339
.remove_one::<String>("index-config")
336340
.map(|uri| Uri::from_str(&uri))
337341
.expect("`index-config` should be a required arg")?;
342+
let create = matches.get_flag("create");
338343
let assume_yes = matches.get_flag("yes");
339344

340345
Ok(Self::Update(UpdateIndexArgs {
341346
index_id,
342347
client_args,
343348
index_config_uri,
349+
create,
344350
assume_yes,
345351
}))
346352
}
@@ -548,7 +554,12 @@ pub async fn update_index_cli(args: UpdateIndexArgs) -> anyhow::Result<()> {
548554
}
549555
qw_client
550556
.indexes()
551-
.update(&args.index_id, &index_config_str, config_format)
557+
.update(
558+
&args.index_id,
559+
&index_config_str,
560+
config_format,
561+
args.create,
562+
)
552563
.await?;
553564
println!("{} Index successfully updated.", "✔".color(GREEN_COLOR));
554565
Ok(())

quickwit/quickwit-cli/src/source.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub fn build_source_command() -> Command {
5757
.required(true),
5858
arg!(--"source-config" <SOURCE_CONFIG> "Path to source config file. Please, refer to the documentation for more details.")
5959
.required(true),
60+
arg!(--"create" "Create the index if it does not already exists.")
61+
.required(false),
6062
])
6163
)
6264
.subcommand(
@@ -162,6 +164,7 @@ pub struct UpdateSourceArgs {
162164
pub index_id: IndexId,
163165
pub source_id: SourceId,
164166
pub source_config_uri: Uri,
167+
pub create: bool,
165168
}
166169

167170
#[derive(Debug, Eq, PartialEq)]
@@ -276,11 +279,14 @@ impl SourceCliCommand {
276279
.remove_one::<String>("source-config")
277280
.map(|uri_str| Uri::from_str(&uri_str))
278281
.expect("`source-config` should be a required arg.")?;
282+
let create = matches.get_flag("create");
283+
279284
Ok(UpdateSourceArgs {
280285
client_args,
281286
index_id,
282287
source_id,
283288
source_config_uri,
289+
create,
284290
})
285291
}
286292

@@ -393,7 +399,12 @@ async fn update_source_cli(args: UpdateSourceArgs) -> anyhow::Result<()> {
393399
let qw_client = args.client_args.client();
394400
qw_client
395401
.sources(&args.index_id)
396-
.update(&args.source_id, source_config_str, config_format)
402+
.update(
403+
&args.source_id,
404+
source_config_str,
405+
config_format,
406+
args.create,
407+
)
397408
.await?;
398409
println!("{} Source successfully updated.", "✔".color(GREEN_COLOR));
399410
Ok(())
@@ -683,6 +694,7 @@ mod tests {
683694
index_id: "hdfs-logs".to_string(),
684695
source_id: "kafka-foo".to_string(),
685696
source_config_uri: Uri::from_str("file:///source-conf.yaml").unwrap(),
697+
create: false,
686698
}));
687699
assert_eq!(command, expected_command);
688700
}

quickwit/quickwit-cli/tests/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ async fn test_cmd_update_index() {
564564
client_args: test_env.default_client_args(),
565565
index_id: index_id.clone(),
566566
index_config_uri: test_env.resource_files.index_config_with_retention.clone(),
567+
create: false,
567568
assume_yes: true,
568569
};
569570
update_index_cli(args).await.unwrap();
@@ -582,6 +583,7 @@ async fn test_cmd_update_index() {
582583
client_args: test_env.default_client_args(),
583584
index_id,
584585
index_config_uri: test_env.resource_files.index_config.clone(),
586+
create: false,
585587
assume_yes: true,
586588
};
587589
update_index_cli(args).await.unwrap();

quickwit/quickwit-integration-tests/src/tests/sqs_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ async fn test_update_source_multi_node_cluster() {
349349
sandbox
350350
.rest_client(QuickwitService::Metastore)
351351
.sources(index_id)
352-
.update(source_id, source_config_input, ConfigFormat::Yaml)
352+
.update(source_id, source_config_input, ConfigFormat::Yaml, false)
353353
.await
354354
.unwrap();
355355

0 commit comments

Comments
 (0)