private void explanWhere(BoolQueryBuilder boolQuery, Where where) throws SqlParseException { while (where.getWheres().size() == 1) { where = where.getWheres().getFirst(); } if (where instanceof Condition) { addSubQuery(boolQuery, where, (BaseQueryBuilder) make((Condition) where)); } else { BoolQueryBuilder subQuery = QueryBuilders.boolQuery(); addSubQuery(boolQuery, where, subQuery); for (Where subWhere : where.getWheres()) { explanWhere(subQuery, subWhere); } } }
/** * 增加嵌套插 * * @param boolQuery * @param where * @param subQuery */ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, BaseQueryBuilder subQuery) { if (where.getConn() == CONN.AND) { boolQuery.must(subQuery); } else { boolQuery.should(subQuery); } }
public SearchResponse search(BaseQueryBuilder xqb, boolean explain, int from, int to) throws ElasticsearchException { SearchResponse response = esclient.client.prepareSearch(index).setSearchType(SearchType.QUERY_THEN_FETCH). setQuery(xqb). setFrom(from).setSize(to). setExplain(explain). execute().actionGet(); return response; }
public long count(BaseQueryBuilder xqb) throws Exception { CountResponse response = esclient.client.prepareCount(index). setQuery(xqb). execute().actionGet(); return response.getCount(); }
public SearchResponse search(BaseQueryBuilder xqb) throws ElasticsearchException { return search(xqb, false, 0, 100); }
public SearchResponse search(BaseQueryBuilder xqb, int from, int to) throws ElasticsearchException { return search(xqb, false, from, to); }