Spring 未在mongoDB中使用@TextIndexed创建文本索引
我有下面的POJO课程Spring 未在mongoDB中使用@TextIndexed创建文本索引,spring,mongodb,spring-data-jpa,spring-data,spring-data-mongodb,Spring,Mongodb,Spring Data Jpa,Spring Data,Spring Data Mongodb,我有下面的POJO课程 @Document("Product") @FieldNameConstants @NoArgsConstructor @Getter @Setter public class Product extends OptimisticLock<Integer>{ @Id private String id; @Field("name") @TextIndexed private Str
@Document("Product")
@FieldNameConstants
@NoArgsConstructor
@Getter
@Setter
public class Product extends OptimisticLock<Integer>{
@Id
private String id;
@Field("name")
@TextIndexed
private String name;
@Field("price")
private float price;
@Field("description")
@TextIndexed(weight = 2)
private String description;
public Product(String name, float price, String description) {
this.name = name;
this.price = price;
this.description = description;
}
}
此迁移使用默认值添加新记录,但不会创建索引。即使我通过禁用迁移来插入记录,它也不会创建索引
我做错的事找不到解决办法
我有以下依赖项
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.springdoc:springdoc-openapi-ui:1.4.3'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
在这里找到了答案
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.springdoc:springdoc-openapi-ui:1.4.3'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}