代码之家  ›  专栏  ›  技术社区  ›  ThatMan

N1QL查询中间歇性遇到“找不到索引”

  •  2
  • ThatMan  · 技术社区  · 7 年前

    用例:搜索“MAYUR”结果出现在搜索中,但如果我搜索“MAY”或“MA”,则没有结果。 我已经实现了一个搜索,它在startsWith(“MAY%”)上搜索。 我使用的是couchbase版本4.6.3-4136-E。

    错误消息如下:

    组织。springframework。数据沙发床。果心CouchbaseQueryExecutionException(CouchbaseQueryExecutionException):
    由于以下n1ql错误,无法执行查询:
    {“msg”:“找不到索引-原因:queryport.indexNotFound”,“代码”:12016}
    {“msg”:“找不到索引-原因:queryport.indexNotFound”,“代码”:12016}
    {“msg”:“找不到索引-原因:queryport.indexNotFound”,“代码”:12016}
    {“msg”:“找不到索引-原因:queryport.indexNotFound”,“代码”:12016}

    Java SDK版本:2.5.5

    我时断时续地面临这个问题。

    运行查询的代码

    public <T> PageImpl<T> runQuery(final Statement statement, final Expression expression, final String alias,
            final Pageable pageable, final Class<T> tClazz) {
        PageImpl<T> tPage = null;
        try {
            CompletableFuture<List<T>> entityFuture = CompletableFuture
                    .supplyAsync(() -> findByN1QLProjection(statement, tClazz)).exceptionally(th -> {
                        logger.write(new Exception(th.getMessage(), th));
                        return Collections.emptyList();
                    });
            CompletableFuture<Long> countFuture = CompletableFuture.supplyAsync(() -> doCount(expression, alias))
                    .exceptionally(th -> {
                        logger.write(new Exception(th.getMessage(), th));
                        return 0L;
                    });
            CompletableFuture.allOf(entityFuture, countFuture).get();
            tPage = new PageImpl<>(entityFuture.get(), pageable, countFuture.get());
        } catch (final InterruptedException | ExecutionException ex) {
            logger.write(ex);
            tPage = new PageImpl<>(Collections.emptyList(), pageable, 0);
        }
        return tPage;
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   ThatMan    7 年前

    根本原因: 查询服务缓存了错误的执行计划,并随后使用了该计划。由于索引id不可用(在重新创建索引时),查询不断抛出错误:“找不到索引”。

    分辨率: 清理存储的准备好的计划后,查询开始工作。