【问题标题】:Remote error from mongot :: caused by :: query has expanded into too many sub-queries internally: maxClauseCount is set to 1024来自 mongot :: 的远程错误由 :: 查询导致内部扩展为太多子查询:maxClauseCount 设置为 1024
【发布时间】: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


    【解决方案1】:

    如果复合查询(即 lucene 布尔查询)中有超过 1024 个术语,则需要进行不同的查询。如果searchTerm 可以小于 1024 个术语,那就没问题了。

    【讨论】:

      猜你喜欢
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      • 2014-03-29
      • 2016-02-14
      相关资源
      最近更新 更多