ElasticSearch学习 -查询ots

ElasticSearch学习 -查询ots,第1张

ElasticSearch学习 -查询ots
//组建SearchRequest 
SearchQuery searchQuery = new SearchQuery();
TermQuery termQuery = new TermQuery(); // 设置查询类型为TermQuery
termQuery.setFieldName("docchannel"); // 设置要匹配的字段
termQuery.setTerm(ColumnValue.fromLong(52L)); // 设置要匹配的值
searchQuery.setQuery(termQuery);
//document:tableName,indexName:document_index
SearchRequest searchRequest = new SearchRequest("document", "document_index", searchQuery);

SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
//1. 返回某个字段,就设置某个字段
List list = new ArrayList<>();
list.add("docchannel");
columnsToGet.setColumns(list);
//2.返回全部字段
//columnsToGet.setReturnAll(true); // 设置返回所有列
searchRequest.setColumnsToGet(columnsToGet);

endPoint: *****   //ots服务器连接地址
accessKeyId: '*****'
accessKeySecret: '******'
instanceName: ****

SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName, clientConfiguration);
SearchResponse resp = client.search(searchRequest);
 List rows = resp.getRows();
   while(resp.getNextToken() != null){
       //把token设置到下一次请求中
       searchRequest.getSearchQuery().setToken(resp.getNextToken());
       resp = client.search(searchRequest);
       if (!resp.isAllSuccess()){
           throw new RuntimeException("not all success");
       }
       rows.addAll(resp.getRows());
   }
   System.out.println("RowSize:" + rows.size());

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5605196.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存