Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.02k stars 1.19k forks source link

Cosmos DB: Missing Composite Index support on Indexing Policy #21115

Closed ealsur closed 1 week ago

ealsur commented 2 years ago

Describe the bug Cosmos DB supports Composite Indexes on Indexing Policy (https://docs.microsoft.com/en-us/azure/cosmos-db/index-policy#composite-indexes) which is supported by all the other Cosmos DB SDKs (.NET, Java, Python, Go).

The NodeJS Cosmos SDK does not support adding Composite Indexes, the Indexing Policy has no such property.

The only way to do it is by doing something like:

const { resource: currentContainer }= await database.container("test").read();
  currentContainer.indexingPolicy = {
    "indexingMode": "consistent",
    "includedPaths": [
      {
        "path": "/*"
      },
      {
        "path": "/view/favorite/?"
      }
    ],
    "excludedPaths": [
      {
        "path": "/\"_etag\"/?"
      }
    ]
  };
  // If composite indexes are needed
  currentContainer.indexingPolicy["compositeIndexes"] = [
    [
      {
        "path": "/view/favorite",
        "order": "descending"
      },
      {
        "path": "/view/displayName/en",
        "order": "descending"
      }
    ],
    [
      {
        "path": "/view/favorite",
        "order": "descending"
      },
      {
        "path": "/view/displayName/en",
        "order": "ascending"
      }
    ]
  ];
  await database.container("test").replace(currentContainer);

To Reproduce Attempt to set the Composite Indexes on an Indexing Policy.

Expected behavior The Indexing Policy has Composite Indexes. Additional context Add any other context about the problem here.

0Dmitry commented 1 year ago

Any updates on that? Just stumbled upon the same issue. In our project we create containers dynamically and recently we got a need for a composite index to be able to order by multiple columns. But turned out it is not possible with nodejs sdk.

sajeetharan commented 1 year ago

Hi @0Dmitry Thanks for reaching out, we still have not started and we will prioritise this and keep you posted.

topshot99 commented 11 months ago

@ealsur Could you assist with PR's(dot-net/java) for the feature described? I've reviewed the documentation and identified potential impacts on various query types beyond adding the 'compositeIndexes' field. Can you provide guidance on necessary actions?

ealsur commented 11 months ago

@topshot99 I don't have any PR links as this is not a new feature.

It all starts with the IndexingPolicy:

https://github.com/Azure/azure-cosmos-dotnet-v3/blob/9f8d84860d3170d8a95b278a51ac2792a927a1ab/Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs#L111-L112

Which leads to the CompositePath: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/9f8d84860d3170d8a95b278a51ac2792a927a1ab/Microsoft.Azure.Cosmos/src/Resource/Settings/CompositePath.cs

github-actions[bot] commented 5 months ago

Hi @ealsur, we deeply appreciate your input into this project. Regrettably, this issue has remained inactive for over 2 years, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

sajeetharan commented 1 week ago

This is already done ! https://devblogs.microsoft.com/cosmosdb/azure-cosmos-db-javascript-sdk-4-1-0-preview-is-here/