使用Java客户端在Couchbase中创建或更新全文搜索

时间:2019-02-11 21:49:11

标签: java couchbase

我正在尝试使用Java客户端UpsertSearchIndexRequest在沙发上创建全文搜索,如文档here所述。但是,我得到一个RequestCancelledException

String payload = null;
    try {
            BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()),1024);
            StringBuilder stringBuilder = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                stringBuilder.append(line).append('\n');
            }
            br.close();
            payload = stringBuilder.toString();
     } catch (Exception e) {
            System.out.println(e);
     }
     CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
             .connectTimeout(60000)
             .retryStrategy(BestEffortRetryStrategy.INSTANCE)
             .queryServiceConfig(QueryServiceConfig.create(2,50))
             .mutationTokensEnabled(true)
             .computationPoolSize(5)
             .build();
    CouchbaseCluster couchbaseCluster = CouchbaseCluster.create(env, "127.0.0.1");

    CouchbaseResponse response = couchbaseCluster.core()
            .send(new UpsertSearchIndexRequest("demoIndex", payload, "null", "password"))
            .toBlocking()
            .single();
    System.out.println(response.status().isSuccess());

当前结果:

  

获取以下异常引起的原因:   com.couchbase.client.core.RequestCancelledException:无法   调度请求,取消而不是重试。在   com.couchbase.client.core.retry.RetryHelper.retryOrCancel(RetryHelper.java:51)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.core.node.locate.QueryLocator.locateAndDispatch(QueryLocator.java:80)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.core.RequestHandler.dispatchRequest(RequestHandler.java:259)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:208)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:79)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:150)   〜[core-io-1.7.2.jar:na]在   com.couchbase.client.deps.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)   〜[core-io-1.7.2.jar:na] at java.lang.Thread.run(Thread.java:748)   〜[na:1.8.0_131]

预期结果:

  

在沙发床中创建/更新索引。

0 个答案:

没有答案