searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); // 查询字段 if(CollectionUtils.isNotEmpty(matchList)){ for (EsMatchSearch esMatchSearch : matchList){ if (matchPhrase == Boolean.TRUE) { boolQuery.must(QueryBuilders.matchPhraseQuery(esMatchSearch.getFieldName(), esMatchSearch.getValue())); } else { boolQuery.must(QueryBuilders.matchQuery(esMatchSearch.getFieldName(), esMatchSearch.getValue())); } } } // 范围查询字段 if(CollectionUtils.isNotEmpty(rangeList)){ for (EsRangeSearch esRangeSearch : rangeList){ RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(esRangeSearch.getFieldName()); if(StringUtils.isNotBlank(esRangeSearch.getFrom())){ rangeQueryBuilder.from(esRangeSearch.getFrom()); } if(StringUtils.isNotBlank(esRangeSearch.getTo())){ rangeQueryBuilder.to(esRangeSearch.getTo()); } rangeQueryBuilder.includeLower(true) .includeUpper(true); boolQuery.must(rangeQueryBuilder); } } searchRequestBuilder.setQuery(boolQuery); // 分页应用 searchRequestBuilder.setFrom(currentPage).setSize(pageSize); // 设置是否按查询匹配度排序 searchRequestBuilder.setExplain(true); // 执行搜索,返回搜索响应信息 SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); long totalHits = searchResponse.getHits().totalHits; long length = searchResponse.getHits().getHits().length; logger.debug("共查询到[{}]条数据,处理数据条数[{}]", totalHits, length);
用查询条件直接在es里查是正常的,通过代码的话结果集里总是少一条记录。求问有可能是什么原因呢?
和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和!