我正在通过 Morphia 并使用 Play 2 在 MongoDB 中的网站中保存搜索日志。该日志具有通常的查询词和结果列表。所以基本上是这样的:
public class SearchLog {
public String query;
@Indexed
@Reference(lazy = true, ignoreMissing = true)
public List<Result> results;
@Indexed
@Embedded
public LocalDateTime timestamp;
}
我根据搜索完成的时间以及结果是否包含“this”来构建查询。
Query q = q().filter("timestamp >=", start).filter("timestamp <=", end)
.field("results").hasThisElement(something).order("timestamp").asList();
数据库中有大约 8000 个日志条目,每个日志包含约 10-20 个结果。我正在测试的这个特定查询返回大约 4000 个条目。但是,即使使用 Index,查询也非常慢(>10 秒)。我做错了什么/有没有办法优化 MongoDB 的查询方式?
谢谢