我有一个api rest,SpringBoot连接到一个mangodb数据库。我在“标题”字段的“技能”集合中创建了一个自动完成索引。我试图用这个索引搜索技能,聚合是:{'$search':{
'autocomplete': {
'query': 'Java',
'path': 'title',
'fuzzy': {
'maxEdits': 2,
'prefixLength': 3
}
}
}
}服务是:
{
MongoCollection<Document> collection = mongoClient.getDatabase("test").getCollection("skills");
BasicDBObject autocomplete = new BasicDBObject ();
autocomplete.append("query", wordToSearch);
autocomplete.append("path", "title");
BasicDBObject autocom = new BasicDBObject ("autocomplete", autocomplete);
BasicDBObject search = new BasicDBObject ("$search", autocom);
logger.info("Search Aggregation " + search.toJson());
List <BasicDBObject> pileline = new ArrayList<BasicDBObject>();
pileline.add(search);
AggregateIterable<Document> result = collection.aggregate(pileline);
return result.first();}
我的休息控制器是:
@GetMapping("/skill/search")
public Document searchSkills(@RequestParam String wordToSearch){
Document skills = skillService.searchSkills(wordToSearch);
return skills;
}
但我得到一个异常:“命令失败,错误为40324(location40324):'无法识别的管道阶段名称:'$search'(服务器上)localhost:27017. 完整响应为{“ok”:0.0,“errmsg”:“unrecognized pipeline stage name:'$search'”,“code”:40324,“codename”:“location40324”}”
谢谢你的帮助!
暂无答案!
目前还没有任何答案,快来回答吧!