弹性DSL查询搜索结果远远优于Rest High Level Client

时间:2019-01-18 15:05:55

标签: elasticsearch elasticsearch-5 elasticsearch-dsl elasticsearch-java-api

我一直在使用Elastic DSLQuerySearchRestHighLevelClient,发现DSLQuerySearch的结果比RestHighLevelClient更好,更具体。我想念什么吗?共享不同的代码

DSLQuerySearch

    String result = a.executeDSLQuerySearch(
            INDEX
            + "/"
            + TYPE
            + "/_search?pretty&filter_path=hits.hits._source&_source=field1,field2,field3",
            searchQuery
    );

与RestHighLevelClient

    SearchRequest searchRequest = new SearchRequest(INDEX);
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.fetchSource(includeFields, excludeFields);

    /* Choose field match or matchAllQuery. */
    searchSourceBuilder.query(QueryBuilders.multiMatchQuery(query, "field1", "field2", "field3"));

    searchSourceBuilder.query(geoDistanceQuery("geo")
            .geohash(geoHash)
            .distance(Constants.MAX_Q_SEARCH_DISTANCE, DistanceUnit.KILOMETERS));
    searchSourceBuilder.sort(new GeoDistanceSortBuilder("geo", geoHash).order(SortOrder.DESC));
    searchSourceBuilder.size(PaginationEnum.TEN.getLimit());
    searchRequest.source(searchSourceBuilder);
    searchRequest.scroll(TimeValue.timeValueMinutes(MINUTES));

    searchResponse = a.restHighLevelClient().search(searchRequest, RequestOptions.DEFAULT);

我期望的结果更加具体。 RestHighLevelClient给出非常通用的结果。 (阅读更多无关的内容),而DSLQuerySearch不在现场。

0 个答案:

没有答案