Azure / azure-cosmosdb-java

Java Async SDK for SQL API of Azure Cosmos DB
MIT License
54 stars 61 forks source link

CosmosDB Client does not create Indexing Policy properly #93

Closed qa-denis-huber closed 5 years ago

qa-denis-huber commented 5 years ago

Describe the bug I am using com.microsoft.azure:azure-cosmosdb:2.4.4. When I send a request to create a collection with IndexingPolicy, the Indexing Policy is not created in Cosmos DB. When I use com.microsoft.azure:azure-cosmosdb:2.3.1 the Indexing Policy is created in Cosmos DB.

To Reproduce I created a minimal example that reproduces the bug: https://github.com/denis-huber-qaware/cosmosdb-indexing-policy. The README contains the steps to run the program.

Here are the relevant lines:

DocumentCollection documentCollection = new DocumentCollection();
documentCollection.setId(COLLECTION);
IndexingPolicy indexingPolicy = new IndexingPolicy();
indexingPolicy.setIndexingMode(IndexingMode.Consistent);
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Index numberIndex = Index.Range(DataType.Number, -1);
Index stringIndex = Index.Range(DataType.String);
includedPath.setIndexes(Arrays.asList(numberIndex, stringIndex));
indexingPolicy.setIncludedPaths(Collections.singletonList(includedPath));
documentCollection.setIndexingPolicy(indexingPolicy);

ResourceResponse<DocumentCollection> response = client.createCollection(String.format("/dbs/%s", DATABASE), documentCollection, null).toBlocking().single();

Source: https://github.com/denis-huber-qaware/cosmosdb-indexing-policy/blob/master/src/main/java/com/example/demo/App.java#L56

Expected behavior I expect, that the Indexing Policy is created with the following value in the Data Explorer in the Microsoft Azure's webapp (https://portal.azure.com):

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"_etag\"/?"
        }
    ]
}

Actual behavior I receive the following Indexing Policy in the webapp (https://portal.azure.com):

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": []
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"_etag\"/?"
        }
    ]
}

Environment summary SDK Version: 2.4.4 Java JDK version:

openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)

OS Version (e.g. Windows, Linux, MacOSX): Linux

phxql commented 5 years ago

Hi, what's the status on this? We're currently using the older version to workaround.

dkroehan commented 5 years ago

Same issue when using com.microsoft.azure:azure-cosmosdb:2.4.5 or com.microsoft.azure:azure-cosmosdb:3.0.0-beta-3

krishnan1985 commented 5 years ago

Hi, As part of the SDK upgrade, we are evolving the index policy to align with a new index layout we have rolled out to new containers. With this new layout, all primitive data types are indexed as Range with full precision (-1), and this is not configurable by the user anymore. Therefore this is not exposed to the user anymore, to avoid confusion. Going forward, users need to simply add paths to the includedPaths section, and ignore indexKinds and precision.

dkroehan commented 5 years ago

Thx for the information! Is this change documented anywhere? Couldn't find it in the changelog.