【发布时间】:2021-10-27 09:45:21
【问题描述】:
我正在使用 MongoDB 的 Atlas Search $search 聚合管道阶段。我收到以下错误:
Remote error from mongot :: caused by :: query has expanded into too many sub-queries internally: maxClauseCount is set to 1024
这似乎是因为 Lucene 的 [maxClauseCount][1] 变量的默认值设置为 1024。
这是我的代码:
const { Restaurant } = require('../models');
Restaurant.aggregate({
$search: {
index: 'default',
compound: {
should: {
{
autocomplete: {
query: filter.searchText,
path: 'name',
},
}
..._.map(mealMatchedRestaurantIds, (id) => {
return {
equals: {
path: '_id',
value: mongoose.Types.ObjectId(id),
},
}
})
},
minimumShouldMatch = 1;
}
}
});
我正在从mealMatchedRestaurantIds 数组中动态生成“等于”子句。该数组的长度超过了 1024,这将导致超过 maxClauseCount 值。
[1]:https://github.com/apache/lucene/search?q=maxClauseCount
MongoDB 是否提供任何 API 来覆盖此变量的值?或者有没有更好的方法来设计这个搜索查询(而不是将它分成多个查询)?
【问题讨论】:
标签: mongodb lucene mongodb-atlas-search