Inconsistencies between DSL queries and Java REST client

Hi all,

I'm trying to perform a simple query using the Java High Level REST API. I'm seeing differences in the results I get.

DSL Query:
{"_source":{"includes":["space","transaction"],"excludes":[]}}
Response:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "areas",
                "_type": "_doc",
                "_id": "areaid115125125115",
                "_score": 1,
                "_source": {}
            },
            {
                "_index": "areas",
                "_type": "_doc",
                "_id": "area1",
                "_score": 1,
                "_source": {
                    "space": "aread1",
                    "transaction": "12345"
                }
            }
        ]
    }
}

Java query:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
    .fetchSource(includes, excludes);
SearchRequest searchRequest = new SearchRequest()
    .source(searchSourceBuilder)
    .indices(index);
    SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);

The problem is that searchResponse.getHits().getTotalHits() is zero, although the hits array contains values:

result = {SearchHits@11296} 
 hits = {SearchHit[2]@11300} 
 totalHits = 0
 maxScore = 1.0
 sortFields = null
 collapseField = null
 collapseValues = null

Has anyone encountered something similar?
Thanks.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.