public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persitentProperty));
public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persitentProperty));
/** * Method ensures that there is a TTL index on {@literal expireAt} field. It's has * {@literal expireAfterSeconds} set to zero seconds, so the expiration time is * controlled by the application. * * It can be extended in custom converters when there is a need for creating * additional custom indexes. * @param sessionCollectionIndexes {@link IndexOperations} to use */ protected void ensureIndexes(IndexOperations sessionCollectionIndexes) { for (IndexInfo info : sessionCollectionIndexes.getIndexInfo()) { if (EXPIRE_AT_FIELD_NAME.equals(info.getName())) { LOG.debug("TTL index on field " + EXPIRE_AT_FIELD_NAME + " already exists"); return; } } LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME); sessionCollectionIndexes .ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0)); }
private void upgradeIndexes() { if (indexNotExists(CONTENT_HASH_INDEX)) { mongoTemplate.indexOps(collectionName).ensureIndex(new Index().on("contentHash", Direction.ASC).named(CONTENT_HASH_INDEX)); } if (indexNotExists(FLOW_NAME_INDEX)) { mongoTemplate.indexOps(collectionName).ensureIndex(new Index().on("flowName", Direction.ASC).named(FLOW_NAME_INDEX)); } }