diff --git a/CosmosDBShell.Tests/CommandTests/MakeContainerCommandTests.cs b/CosmosDBShell.Tests/CommandTests/MakeContainerCommandTests.cs index 7a0c5da5..23366a1d 100644 --- a/CosmosDBShell.Tests/CommandTests/MakeContainerCommandTests.cs +++ b/CosmosDBShell.Tests/CommandTests/MakeContainerCommandTests.cs @@ -9,6 +9,21 @@ namespace CosmosShell.Tests.CommandTests; public class MakeContainerCommandTests { + [Theory] + [InlineData("{")] + [InlineData("null")] + [InlineData("""{"defaultLanguage":" ","fullTextPaths":[{"path":"/description","language":"en-US"}]}""")] + [InlineData("""{"defaultLanguage":"en-US","fullTextPaths":[]}""")] + [InlineData("""{"defaultLanguage":"en-US","fullTextPaths":[{"path":"description","language":"en-US"}]}""")] + [InlineData("""{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description"}]}""")] + [InlineData("""{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description","language":"en-US","unexpected":true}]}""")] + [InlineData("""{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description","language":"en-US"},{"path":"/description","language":"fr-FR"}]}""")] + public void FullTextPolicy_RejectsInvalidInput(string json) + { + Assert.ThrowsAny(() => + Azure.Data.Cosmos.Shell.Core.ContainerFullTextPolicyInput.Parse(json)); + } + [Fact] public void CreateContainerProperties_HierarchicalPartitionKey_KeepsAllPaths() { diff --git a/CosmosDBShell.Tests/CommandTests/ResourceCreationResultTests.cs b/CosmosDBShell.Tests/CommandTests/ResourceCreationResultTests.cs index 009481e6..c1b79ef2 100644 --- a/CosmosDBShell.Tests/CommandTests/ResourceCreationResultTests.cs +++ b/CosmosDBShell.Tests/CommandTests/ResourceCreationResultTests.cs @@ -23,6 +23,66 @@ namespace CosmosShell.Tests.CommandTests; [Collection(ConsoleOutputTestCollection.Name)] public class ResourceCreationResultTests { + private const string FullTextPolicyJson = """{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description","language":"en-US"}]}"""; + + [Fact] + public async Task FullTextPolicy_ArmRejectsBeforeAnyResourceCall() + { + using var shell = ShellInterpreter.CreateInstance(); + var context = ConfigureArm(); + context.Account.ClearReceivedCalls(); + shell.State = new ConnectedState(Substitute.For(), context); + var command = new MakeContainerCommand { Name = "Items", PartitionKey = "/pk", Database = "db", FullTextPolicyJson = FullTextPolicyJson }; + + var error = await Assert.ThrowsAsync(() => + command.ExecuteAsync(shell, new CommandState(), "mkcon", TestContext.Current.CancellationToken)); + + Assert.Contains("not supported on the Azure Resource Manager route", error.Message); + Assert.Empty(context.Account.ReceivedCalls()); + } + + [Fact] + public async Task FullTextPolicy_ExistingContainerRemainsExisting() + { + using var shell = ShellInterpreter.CreateInstance(); + var client = Substitute.For(); + ConfigureDataPlane(client, created: false); + shell.State = new ConnectedState(client); + var command = new MakeContainerCommand { Name = "Items", PartitionKey = "/pk", Database = "db", FullTextPolicyJson = FullTextPolicyJson }; + + var state = await command.ExecuteAsync(shell, new CommandState(), "mkcon", TestContext.Current.CancellationToken); + + var result = Assert.IsType(state.Result).Value; + Assert.False(result.GetProperty("created").GetBoolean()); + Assert.Equal("existing", result.GetProperty("outcome").GetString()); + } + + [Fact] + public async Task FullTextPolicy_ServiceRejectionIsNotRetriedWithoutPolicy() + { + using var shell = ShellInterpreter.CreateInstance(); + var client = Substitute.For(); + ConfigureDataPlane(client, created: true); + var database = client.GetDatabase("db"); + const string message = "Full-text search is not supported on this account."; + var error = new CosmosException(message, HttpStatusCode.BadRequest, 0, "test", 0); + database.CreateContainerIfNotExistsAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(Task.FromException(error)); + shell.State = new ConnectedState(client); + var command = new MakeContainerCommand { Name = "Items", PartitionKey = "/pk", Database = "db", FullTextPolicyJson = FullTextPolicyJson }; + + var actual = await Assert.ThrowsAsync(() => + command.ExecuteAsync(shell, new CommandState(), "mkcon", TestContext.Current.CancellationToken)); + + Assert.Contains(message, actual.Message); + await database.Received(1).CreateContainerIfNotExistsAsync( + Arg.Is(properties => properties.FullTextPolicy != null), + Arg.Any(), + Arg.Any(), + Arg.Any()); + await database.ReceivedWithAnyArgs(1).CreateContainerIfNotExistsAsync(default!, default(ThroughputProperties), default, TestContext.Current.CancellationToken); + } + public static IEnumerable CreationCases() { foreach (var container in new[] { false, true }) diff --git a/CosmosDBShell.Tests/ToolOperationsCallToolTests.cs b/CosmosDBShell.Tests/ToolOperationsCallToolTests.cs index f0b38315..7ed5d13f 100644 --- a/CosmosDBShell.Tests/ToolOperationsCallToolTests.cs +++ b/CosmosDBShell.Tests/ToolOperationsCallToolTests.cs @@ -140,6 +140,98 @@ private static JsonElement Json(string raw) return document.RootElement.Clone(); } + [Theory] + [InlineData("mkcon", false)] + [InlineData("create", false)] + [InlineData("mkcon", true)] + [InlineData("create", true)] + public async Task ContainerCreation_ForwardsFullTextPolicy(string command, bool useMcp) + { + const string policy = """{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description","language":"en-US"},{"path":"/notes/[]","language":"fr-FR"}]}"""; + var shell = ShellInterpreter.Instance; + var originalState = shell.State; + var client = Substitute.For(); + client.Endpoint.Returns(new Uri("https://example.invalid")); + var db = Substitute.For(); + var dbResponse = Substitute.For(); + dbResponse.StatusCode.Returns(System.Net.HttpStatusCode.OK); + db.ReadAsync(cancellationToken: Arg.Any()).Returns(dbResponse); + client.GetDatabase("shop").Returns(db); + var response = Substitute.For(); + response.StatusCode.Returns(System.Net.HttpStatusCode.Created); + response.Container.Id.Returns("products"); + ContainerProperties? sent = null; + db.CreateContainerIfNotExistsAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(call => + { + sent = call.Arg(); + return response; + }); + + try + { + shell.State = new DatabaseState("shop", client); + if (useMcp) + { + var tool = this.CreateToolOperations(); + var tools = await tool.ListToolsHandler(ListContext(), TestContext.Current.CancellationToken); + var schema = Assert.Single(tools.Tools, entry => entry.Name == command).InputSchema; + Assert.Equal("object", schema.GetProperty("properties").GetProperty("full-text-policy").GetProperty("type").GetString()); + var arguments = new Dictionary + { + ["name"] = Json("\"products\""), + ["partition_key"] = Json("\"/tenantId\""), + ["full-text-policy"] = Json(policy), + }; + if (command == "create") + { + arguments["item"] = Json("\"container\""); + } + + var result = await tool.CallToolHandler(CallContext(command, arguments), TestContext.Current.CancellationToken); + Assert.False(result.IsError == true, Assert.IsType(Assert.Single(result.Content)).Text); + } + else + { + var verb = command == "create" ? "create container" : "mkcon"; + var result = await shell.ExecuteCommandAsync($"{verb} products /tenantId --full-text-policy='{policy}'", TestContext.Current.CancellationToken); + Assert.False(result.IsError, result.GenerateOutputText()); + } + + var actual = Assert.IsType(sent?.FullTextPolicy); + Assert.Equal("en-US", actual.DefaultLanguage); + Assert.Collection( + actual.FullTextPaths, + first => Assert.Equal(("/description", "en-US"), (first.Path, first.Language)), + second => Assert.Equal(("/notes/[]", "fr-FR"), (second.Path, second.Language))); + } + finally + { + shell.State = originalState; + } + } + + [Theory] + [InlineData("null")] + [InlineData("\"{}\"")] + [InlineData("[]")] + public async Task ContainerCreation_McpRequiresAnObject(string policy) + { + var arguments = new Dictionary + { + ["name"] = Json("\"products\""), + ["partition_key"] = Json("\"/tenantId\""), + ["full-text-policy"] = Json(policy), + }; + var result = await this.CreateToolOperations().CallToolHandler(CallContext("mkcon", arguments), TestContext.Current.CancellationToken); + var (isError, root, document) = ReadResult(result); + using (document) + { + Assert.True(isError); + Assert.Contains("Expected a JSON object", root.GetProperty("error").GetString()); + } + } + private static (bool IsError, JsonElement Root, JsonDocument Document) ReadResult(CallToolResult result) { var text = Assert.IsType(Assert.Single(result.Content)).Text; diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs index 1329a89b..b6025541 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs @@ -46,12 +46,20 @@ internal class CreateCommand : CosmosCommand [CosmosOption("index_policy", "ip")] public string? IndexPolicy { get; init; } + [CosmosOption(ContainerFullTextPolicyInput.OptionName)] + public string? FullTextPolicyJson { get; init; } + [CosmosOption("force", "upsert")] public bool? Force { get; init; } public async override Task ExecuteAsync(ShellInterpreter shell, CommandState commandState, string commandText, CancellationToken token) { var item = (this.Item ?? string.Empty).ToUpper(); + if (this.FullTextPolicyJson is not null && !IsContainer(item)) + { + throw CommandException.Usage("create", MessageService.GetString("command-create-error-full-text-policy-container-only")); + } + if (IsItem(item)) { var mkItemCmd = new MakeItemCommand() @@ -93,6 +101,7 @@ public async override Task ExecuteAsync(ShellInterpreter shell, Co MaxRU = this.MaxRU, Database = this.Database, IndexPolicy = this.IndexPolicy, + FullTextPolicyJson = this.FullTextPolicyJson, }, shell, token); diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs index 75099806..6caa15ef 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs @@ -53,6 +53,9 @@ internal class MakeContainerCommand : CosmosCommand, IStateVisitor ExecuteAsync(ShellInterpreter shell, CommandState commandState, string commandText, CancellationToken token) { return await shell.State.AcceptAsync(this, shell, token); @@ -146,6 +149,24 @@ Task IStateVisitor.VisitContainerS private async Task CreateContainerInDatabaseAsync(ConnectedState state, ShellInterpreter shell, string databaseName, CancellationToken token) { + FullTextPolicy? fullTextPolicy = null; + if (this.FullTextPolicyJson is not null) + { + try + { + fullTextPolicy = ContainerFullTextPolicyInput.Parse(this.FullTextPolicyJson); + } + catch (Exception ex) when (ex is JsonException or ArgumentException) + { + throw CommandException.Usage("mkcon", MessageService.GetArgsString("command-mkcon-error-invalid-full-text-policy", "detail", ex.Message), ex); + } + + if (state.ArmContext is not null) + { + throw CommandException.Usage("mkcon", MessageService.GetString("command-mkcon-error-full-text-policy-arm")); + } + } + // Validate database exists await ValidateDatabaseExistsAsync(state, databaseName, "mkcon", token); @@ -162,7 +183,8 @@ private async Task CreateContainerInDatabaseAsync(ConnectedState s this.IndexPolicy, this.Scale, this.MaxRU, - token); + token, + fullTextPolicy); } catch (InvalidIndexingPolicyJsonException ex) { diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs index 988125cf..09126cb9 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs @@ -7,6 +7,7 @@ namespace Azure.Data.Cosmos.Shell.Core; using System.Linq; using System.Net; using System.Runtime.CompilerServices; +using Azure.Data.Cosmos.Shell.Util; using global::Azure; using global::Azure.ResourceManager.CosmosDB.Models; @@ -70,8 +71,14 @@ public async Task CreateContainerAsync( string? indexPolicyJson, string? scale, int? maxRu, - CancellationToken token) + CancellationToken token, + Microsoft.Azure.Cosmos.FullTextPolicy? fullTextPolicy = null) { + if (fullTextPolicy is not null) + { + throw new NotSupportedException(MessageService.GetString("command-mkcon-error-full-text-policy-arm")); + } + CosmosDBIndexingPolicy? parsedIndex = null; if (!string.IsNullOrWhiteSpace(indexPolicyJson)) { diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ContainerFullTextPolicyInput.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ContainerFullTextPolicyInput.cs new file mode 100644 index 00000000..0f051208 --- /dev/null +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ContainerFullTextPolicyInput.cs @@ -0,0 +1,70 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// ------------------------------------------------------------ + +namespace Azure.Data.Cosmos.Shell.Core; + +using System.Collections.ObjectModel; +using System.Text.Json; +using Microsoft.Azure.Cosmos; + +internal static class ContainerFullTextPolicyInput +{ + public const string OptionName = "full-text-policy"; + + public static FullTextPolicy Parse(string json) + { + using var document = JsonDocument.Parse(json); + var root = document.RootElement; + ValidateProperties(root, "defaultLanguage", "fullTextPaths"); + var defaultLanguage = ReadString(root, "defaultLanguage"); + if (!root.TryGetProperty("fullTextPaths", out var paths) || paths.ValueKind != JsonValueKind.Array || paths.GetArrayLength() == 0) + { + throw new JsonException("'fullTextPaths' must be a non-empty array."); + } + + var entries = new Collection(); + var seenPaths = new HashSet(StringComparer.Ordinal); + foreach (var entry in paths.EnumerateArray()) + { + ValidateProperties(entry, "path", "language"); + var path = ReadString(entry, "path"); + if (path.Length < 2 || path[0] != '/' || !seenPaths.Add(path)) + { + throw new JsonException("Each full-text path must start with '/', name a property, and appear only once."); + } + + entries.Add(new FullTextPath { Path = path, Language = ReadString(entry, "language") }); + } + + return new FullTextPolicy { DefaultLanguage = defaultLanguage, FullTextPaths = entries }; + } + + private static void ValidateProperties(JsonElement element, string first, string second) + { + if (element.ValueKind != JsonValueKind.Object) + { + throw new JsonException("Expected a JSON object."); + } + + var names = new HashSet(StringComparer.Ordinal); + foreach (var property in element.EnumerateObject()) + { + if ((property.Name != first && property.Name != second) || !names.Add(property.Name)) + { + throw new JsonException($"Expected only '{first}' and '{second}', each specified once."); + } + } + } + + private static string ReadString(JsonElement element, string name) + { + if (!element.TryGetProperty(name, out var value) || value.ValueKind != JsonValueKind.String + || value.GetString() is not { } text || string.IsNullOrWhiteSpace(text)) + { + throw new JsonException($"'{name}' must be a non-blank string."); + } + + return text; + } +} diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs index 14a5d4eb..562063d4 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs @@ -5,6 +5,7 @@ namespace Azure.Data.Cosmos.Shell.Core; using Azure.Data.Cosmos.Shell.States; +using Microsoft.Azure.Cosmos; /// /// Resource access facade for database and container operations. Commands use this @@ -47,9 +48,10 @@ public static Task CreateContainerAsync( string? indexPolicyJson, string? scale, int? maxRu, - CancellationToken token) + CancellationToken token, + FullTextPolicy? fullTextPolicy = null) { - return For(state).CreateContainerAsync(databaseName, containerName, partitionKeyPaths, uniqueKey, indexPolicyJson, scale, maxRu, token); + return For(state).CreateContainerAsync(databaseName, containerName, partitionKeyPaths, uniqueKey, indexPolicyJson, scale, maxRu, token, fullTextPolicy); } public static Task DeleteDatabaseAsync(ConnectedState state, string databaseName, CancellationToken token) diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs index cf7aa04a..bf9b80c6 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs @@ -97,7 +97,8 @@ public async Task CreateContainerAsync( string? indexPolicyJson, string? scale, int? maxRu, - CancellationToken token) + CancellationToken token, + FullTextPolicy? fullTextPolicy = null) { var props = partitionKeyPaths.Count > 1 ? new ContainerProperties(containerName, partitionKeyPaths.ToList()) @@ -119,6 +120,11 @@ public async Task CreateContainerAsync( props.IndexingPolicy = ParseIndexingPolicy(indexPolicyJson); } + if (fullTextPolicy is not null) + { + props.FullTextPolicy = fullTextPolicy; + } + var database = client.GetDatabase(databaseName); var response = await CreateWithServerlessFallbackAsync( scale, diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs index bd632d28..6f7152b5 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs @@ -4,6 +4,8 @@ namespace Azure.Data.Cosmos.Shell.Core; +using Microsoft.Azure.Cosmos; + internal interface ICosmosResourceOperations { IAsyncEnumerable GetDatabaseNamesAsync(CancellationToken token); @@ -24,7 +26,8 @@ Task CreateContainerAsync( string? indexPolicyJson, string? scale, int? maxRu, - CancellationToken token); + CancellationToken token, + FullTextPolicy? fullTextPolicy = null); Task DeleteDatabaseAsync(string databaseName, CancellationToken token); diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs index 94fd96ec..49ebac19 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs @@ -379,7 +379,30 @@ private static bool IsPagedMaxOption(CommandFactory command, Option option) private static JsonObject CreatePropertySchema(Type propertyType, string? description, string[] names, object? defaultValue = null) { - var schema = CreateTypeSchema(propertyType); + var schema = names[0] == ContainerFullTextPolicyInput.OptionName + ? JsonNode.Parse(""" + { + "type": "object", + "required": ["defaultLanguage", "fullTextPaths"], + "additionalProperties": false, + "properties": { + "defaultLanguage": { "type": "string", "minLength": 1 }, + "fullTextPaths": { + "type": "array", "minItems": 1, + "items": { + "type": "object", + "required": ["path", "language"], + "additionalProperties": false, + "properties": { + "path": { "type": "string", "pattern": "^/.+" }, + "language": { "type": "string", "minLength": 1 } + } + } + } + } + } + """)!.AsObject() + : CreateTypeSchema(propertyType); var descriptionText = description ?? string.Empty; if (names.Length > 1) @@ -495,9 +518,23 @@ private static bool IsExplicitJsonNull(JsonElement value) var targetType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; try { - convertedValue = rawValue is JsonElement jsonElement - ? ConvertJsonElement(jsonElement, targetType) - : Convert.ChangeType(rawValue, targetType, CultureInfo.InvariantCulture); + if (memberDisplay == $"--{ContainerFullTextPolicyInput.OptionName}") + { + if (rawValue is not JsonElement { ValueKind: JsonValueKind.Object } policy) + { + var message = $"Invalid value for option '{memberDisplay}' on command '{commandName}'. Expected a JSON object."; + this.logger?.LogWarning("{Message}", message); + return McpResponseFactory.CreateError(message, ShellInterpreter.Instance.State); + } + + convertedValue = policy.GetRawText(); + } + else + { + convertedValue = rawValue is JsonElement jsonElement + ? ConvertJsonElement(jsonElement, targetType) + : Convert.ChangeType(rawValue, targetType, CultureInfo.InvariantCulture); + } } catch (Exception ex) { @@ -597,7 +634,7 @@ private async ValueTask OnCallToolsAsync( var option = command.Options.FirstOrDefault(a => MatchesArgumentName(a.Name, par.Key)); if (option != null) { - if (IsExplicitJsonNull(par.Value)) + if (IsExplicitJsonNull(par.Value) && option.Name[0] != ContainerFullTextPolicyInput.OptionName) { var safetyErrorKey = cmd is RmCommand ? option.PropertyInfo.Name switch diff --git a/CosmosDBShell/lang/en.ftl b/CosmosDBShell/lang/en.ftl index 4c7bbe73..3790fbd3 100644 --- a/CosmosDBShell/lang/en.ftl +++ b/CosmosDBShell/lang/en.ftl @@ -675,7 +675,12 @@ command-mkcon-container_created_or_updated = Created or updated container { $con command-mkcon-error_partition_key_empty = Partition key path cannot be empty. Provide a path that starts with '/', for example: mkcon name /pk. command-mkcon-error_partition_key_slash = Partition key path must start with a forward slash (/), for example: mkcon name /pk. command-mkcon-error_invalid_index_policy = Invalid indexing policy JSON. Please provide a valid Cosmos DB indexing policy. +command-mkcon-error-invalid-full-text-policy = Invalid full-text policy: { $detail } +command-mkcon-error-full-text-policy-arm = The --full-text-policy option requires a data-plane connection that can create containers without updating existing ones. It is not supported on the Azure Resource Manager route. +command-create-error-full-text-policy-container-only = The --full-text-policy option is only supported by create container. command-mkcon-description-index_policy = The indexing policy as a JSON string. Follows the Cosmos DB indexing policy schema. +command-mkcon-description-full-text-policy = The container full-text policy. Pass a JSON object as a quoted value in the shell. Supported for new containers on data-plane connections only. +command-create-description-full-text-policy = { command-mkcon-description-full-text-policy } command-schema-description = Infers the schema of a container from a bounded sample and returns its partition key, indexing policy summary, an estimated document count, and inferred field types. command-schema-description-database = The database containing the container diff --git a/docs/commands.md b/docs/commands.md index 7c10ac44..8878e585 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -1109,6 +1109,16 @@ Examples: Unlike `mkdb`, container creation on provisioned accounts still defaults to dedicated autoscale throughput with a maximum of 1000 RU/s. On serverless accounts, omit both options: data-plane connections retry without throughput when the service rejects the default throughput, and ARM connections omit it directly. Explicit `--scale` or `--ru` options are rejected on serverless accounts. +Use `--full-text-policy` with `mkcon` or `create container` to specify the container policy as a quoted JSON object: + +```text +mkcon Products /tenantId --database=ExampleShop --full-text-policy='{"defaultLanguage":"en-US","fullTextPaths":[{"path":"/description","language":"en-US"}]}' +``` + +Provide `defaultLanguage` and a non-empty `fullTextPaths` array of `path`/`language` objects. This option is separate from `--index_policy`, which can specify `fullTextIndexes` for the same paths. Use the exact service language codes and check the [Cosmos DB full-text search requirements](https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search), including preview enrollment and regional availability for additional languages. The shell does not enable account features. + +The option applies only to new containers on data-plane connections. An existing container is not modified; use `info` to inspect its policy. The ARM route rejects this option because its create-or-update operation does not guarantee create-only behavior. + `create database` follows the `mkdb` defaults; `create container` follows the `mkcon` defaults. ### rmdb diff --git a/docs/mcp.md b/docs/mcp.md index 5f8f523c..112e88d9 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -152,6 +152,8 @@ Database and container resource actions are executed through Azure Resource Mana On serverless accounts, `mkdb`, `mkcon`, and their `create` aliases omit throughput when neither `--scale` nor `--ru` is supplied. Explicit throughput options are rejected on serverless accounts for both ARM and data-plane connections. See [database and container creation](commands.md#mkdb). +For `mkcon` and `create` with `item: "container"`, pass `full-text-policy` as a JSON object with `defaultLanguage` and `fullTextPaths`, not as a JSON-encoded string. It applies only to new containers on data-plane connections and is separate from `index_policy`. See [container creation](commands.md#mkcon) for an example and prerequisites. + For deterministic ARM routing in multi-subscription environments, start the shell with `--connect-subscription` and `--connect-resource-group`. MCP `import` uses the same bounded concurrency as the CLI: up to 16 writes in flight by default, configurable with the `concurrency` argument. Its schema requires a positive integer (`minimum: 1`). Use `concurrency: 1` for sequential, file-order writes. In-flight writes may complete after an error; imports are not transactional. See [import](commands.md#import) for error and cancellation behavior. diff --git a/l10n/CosmosDBShell.json b/l10n/CosmosDBShell.json index 2fa29dc8..0d9ee976 100644 --- a/l10n/CosmosDBShell.json +++ b/l10n/CosmosDBShell.json @@ -294,6 +294,7 @@ "command-create-description-data": "JSON data for the item to create", "command-create-description-database": "The database for the create operation", "command-create-description-force": "{0}", + "command-create-description-full-text-policy": "{0}", "command-create-description-index_policy": "{0}", "command-create-description-item": "The object to create item, container or database.", "command-create-description-name": "The container or database name to create.", @@ -304,6 +305,7 @@ "command-create-error-container_name_required": "Create container requires a container name.", "command-create-error-database_name_required": "Create database requires a database name.", "command-create-error-force_only_for_items": "The --force/--upsert option is only valid for \u0060create item\u0060.", + "command-create-error-full-text-policy-container-only": "The --full-text-policy option is only supported by create container.", "command-create-error-invalid_item_type": "{0}", "command-create-error-partition_key_required": "Create container requires a partition key path that starts with \u0027/\u0027, for example: create container name /pk. Learn more: https://github.com/Azure/CosmosDBShell/blob/main/docs/commands.md#create", "command-create-example-1": "Create a new container with partition key", @@ -621,12 +623,15 @@ "command-mkcon-container_existing": "Using existing container {0}", "command-mkcon-description": "Creates a new container in the current database.", "command-mkcon-description-database": "The database where the container should be created", + "command-mkcon-description-full-text-policy": "The container full-text policy. Pass a JSON object as a quoted value in the shell. Supported for new containers on data-plane connections only.", "command-mkcon-description-index_policy": "The indexing policy as a JSON string. Follows the Cosmos DB indexing policy schema.", "command-mkcon-description-name": "The container to create.", "command-mkcon-description-partition_key": "The partition key path(s) for the container. Use a single path (e.g. /categoryId) or comma-separated paths for hierarchical partition keys (e.g. /tenantId,/userId or /tenantId,/userId,/sessionId).", "command-mkcon-description-ru": "Container max RU/s (default: 1000; omitted on serverless accounts)", "command-mkcon-description-scale": "Container throughput mode (manual or auto). Not supported on serverless accounts.", "command-mkcon-description-unique_key": "The unique keys for the container to create.", + "command-mkcon-error-full-text-policy-arm": "The --full-text-policy option requires a data-plane connection that can create containers without updating existing ones. It is not supported on the Azure Resource Manager route.", + "command-mkcon-error-invalid-full-text-policy": "Invalid full-text policy: {0}", "command-mkcon-error_invalid_index_policy": "Invalid indexing policy JSON. Please provide a valid Cosmos DB indexing policy.", "command-mkcon-error_partition_key_empty": "Partition key path cannot be empty. Provide a path that starts with \u0027/\u0027, for example: mkcon name /pk.", "command-mkcon-error_partition_key_slash": "Partition key path must start with a forward slash (/), for example: mkcon name /pk.",