use of com.azure.cosmos.models.IncludedPath in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method MigrateJavaSDKv4IndexingAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/migrate-java-v4-sdk
* Indexing
*/
/**
* Indexing
*/
public static void MigrateJavaSDKv4IndexingAsync() {
String containerName = "family_container";
String partition_key = "/pk";
CosmosAsyncDatabase database = null;
// <MigrateIndexingAsync>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Custom indexing policy
IndexingPolicy indexingPolicy = new IndexingPolicy();
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
containerProperties.setIndexingPolicy(indexingPolicy);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
database.createContainerIfNotExists(containerProperties, throughputProperties);
CosmosAsyncContainer containerIfNotExists = database.getContainer(containerName);
// </MigrateIndexingAsync>
}
use of com.azure.cosmos.models.IncludedPath in project scalardb by scalar-labs.
the class CosmosAdmin method computeContainerProperties.
private CosmosContainerProperties computeContainerProperties(String table, TableMetadata metadata) {
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> paths = new ArrayList<>();
if (metadata.getClusteringKeyNames().isEmpty()) {
paths.add(new IncludedPath(PARTITION_KEY_PATH + "/?"));
} else {
// Add a composite index when we have clustering keys
List<CompositePath> compositePaths = new ArrayList<>();
// Add concatenated partition key to the composite path first
CompositePath partitionKeyCompositePath = new CompositePath();
partitionKeyCompositePath.setPath(PARTITION_KEY_PATH);
partitionKeyCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
compositePaths.add(partitionKeyCompositePath);
// Then, add clustering keys to the composite path
metadata.getClusteringKeyNames().forEach(c -> {
CompositePath compositePath = new CompositePath();
compositePath.setPath(CLUSTERING_KEY_PATH_PREFIX + c);
compositePath.setOrder(metadata.getClusteringOrder(c) == Order.ASC ? CompositePathSortOrder.ASCENDING : CompositePathSortOrder.DESCENDING);
compositePaths.add(compositePath);
});
indexingPolicy.setCompositeIndexes(Collections.singletonList(compositePaths));
}
paths.addAll(metadata.getSecondaryIndexNames().stream().map(index -> new IncludedPath(SECONDARY_INDEX_KEY_PATH_PREFIX + index + "/?")).collect(Collectors.toList()));
if (!paths.isEmpty()) {
indexingPolicy.setIncludedPaths(paths);
}
indexingPolicy.setExcludedPaths(Collections.singletonList(new ExcludedPath(EXCLUDED_PATH)));
return new CosmosContainerProperties(table, PARTITION_KEY_PATH).setIndexingPolicy(indexingPolicy);
}
use of com.azure.cosmos.models.IncludedPath in project scalardb by scalar-labs.
the class CosmosAdmin method computeIndexingPolicy.
private IndexingPolicy computeIndexingPolicy(TableMetadata metadata) {
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> paths = new ArrayList<>();
if (metadata.getClusteringKeyNames().isEmpty()) {
paths.add(new IncludedPath(PARTITION_KEY_PATH + "/?"));
} else {
// Add a composite index when we have clustering keys
List<CompositePath> compositePaths = new ArrayList<>();
// Add concatenated partition key to the composite path first
CompositePath partitionKeyCompositePath = new CompositePath();
partitionKeyCompositePath.setPath(PARTITION_KEY_PATH);
partitionKeyCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
compositePaths.add(partitionKeyCompositePath);
// Then, add clustering keys to the composite path
metadata.getClusteringKeyNames().forEach(c -> {
CompositePath compositePath = new CompositePath();
compositePath.setPath(CLUSTERING_KEY_PATH_PREFIX + c);
compositePath.setOrder(metadata.getClusteringOrder(c) == Order.ASC ? CompositePathSortOrder.ASCENDING : CompositePathSortOrder.DESCENDING);
compositePaths.add(compositePath);
});
indexingPolicy.setCompositeIndexes(Collections.singletonList(compositePaths));
}
paths.addAll(metadata.getSecondaryIndexNames().stream().map(index -> new IncludedPath(SECONDARY_INDEX_KEY_PATH_PREFIX + index + "/?")).collect(Collectors.toList()));
if (!paths.isEmpty()) {
indexingPolicy.setIncludedPaths(paths);
}
indexingPolicy.setExcludedPaths(Collections.singletonList(new ExcludedPath(EXCLUDED_PATH)));
return indexingPolicy;
}
use of com.azure.cosmos.models.IncludedPath in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagementAsync method createContainerIfNotExistsWithSpecifiedIndex.
private void createContainerIfNotExistsWithSpecifiedIndex() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
// <CreateContainerIfNotExists>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// <CustomIndexingPolicy>
IndexingPolicy indexingPolicy = new IndexingPolicy();
// To turn indexing off set IndexingMode.NONE
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
// Spatial indices - if you need them, here is how to set them up:
/*
List<SpatialSpec> spatialIndexes = new ArrayList<SpatialSpec>();
List<SpatialType> collectionOfSpatialTypes = new ArrayList<SpatialType>();
SpatialSpec spec = new SpatialSpec();
spec.setPath("/locations/*");
collectionOfSpatialTypes.add(SpatialType.Point);
spec.setSpatialTypes(collectionOfSpatialTypes);
spatialIndexes.add(spec);
indexingPolicy.setSpatialIndexes(spatialIndexes);
*/
// Composite indices - if you need them, here is how to set them up:
/*
List<List<CompositePath>> compositeIndexes = new ArrayList<>();
List<CompositePath> compositePaths = new ArrayList<>();
CompositePath nameCompositePath = new CompositePath();
nameCompositePath.setPath("/name");
nameCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
CompositePath ageCompositePath = new CompositePath();
ageCompositePath.setPath("/age");
ageCompositePath.setOrder(CompositePathSortOrder.DESCENDING);
compositePaths.add(ageCompositePath);
compositePaths.add(nameCompositePath);
compositeIndexes.add(compositePaths);
indexingPolicy.setCompositeIndexes(compositeIndexes);
*/
containerProperties.setIndexingPolicy(indexingPolicy);
// </CustomIndexingPolicy>
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
Mono<CosmosContainerResponse> containerIfNotExists = database.createContainerIfNotExists(containerProperties, throughputProperties);
// Create container with 400 RU/s
containerIfNotExists.flatMap(containerResponse -> {
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Checking container " + container.getId() + " completed!\n");
return Mono.empty();
}).block();
// </CreateContainerIfNotExists>
}
use of com.azure.cosmos.models.IncludedPath in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagement method createContainerIfNotExistsWithSpecifiedIndex.
private void createContainerIfNotExistsWithSpecifiedIndex() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// <CustomIndexingPolicy>
IndexingPolicy indexingPolicy = new IndexingPolicy();
// To turn indexing off set IndexingMode.NONE
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
// Spatial indices - if you need them, here is how to set them up:
/*
List<SpatialSpec> spatialIndexes = new ArrayList<SpatialSpec>();
List<SpatialType> collectionOfSpatialTypes = new ArrayList<SpatialType>();
SpatialSpec spec = new SpatialSpec();
spec.setPath("/locations/*");
collectionOfSpatialTypes.add(SpatialType.Point);
spec.setSpatialTypes(collectionOfSpatialTypes);
spatialIndexes.add(spec);
indexingPolicy.setSpatialIndexes(spatialIndexes);
*/
// Composite indices - if you need them, here is how to set them up:
/*
List<List<CompositePath>> compositeIndexes = new ArrayList<>();
List<CompositePath> compositePaths = new ArrayList<>();
CompositePath nameCompositePath = new CompositePath();
nameCompositePath.setPath("/name");
nameCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
CompositePath ageCompositePath = new CompositePath();
ageCompositePath.setPath("/age");
ageCompositePath.setOrder(CompositePathSortOrder.DESCENDING);
compositePaths.add(ageCompositePath);
compositePaths.add(nameCompositePath);
compositeIndexes.add(compositePaths);
indexingPolicy.setCompositeIndexes(compositeIndexes);
*/
containerProperties.setIndexingPolicy(indexingPolicy);
// </CustomIndexingPolicy>
// Create container with 400 RU/s
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Checking container " + container.getId() + " completed!\n");
}
Aggregations