# Inconsistencies between DSL queries and Java REST client

**URL:** <https://discuss.elastic.co/t/inconsistencies-between-dsl-queries-and-java-rest-client/186137>\
**Category:** Elasticsearch\
**Created:** [June 17, 2019, 6:39pm UTC](https://discuss.elastic.co/t/inconsistencies-between-dsl-queries-and-java-rest-client/186137 "2019-06-17T18:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilg02](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@emilg02](https://discuss.elastic.co/u/emilg02)\
**Post date:** [June 17, 2019, 6:39pm UTC](https://discuss.elastic.co/t/inconsistencies-between-dsl-queries-and-java-rest-client/186137/1 "2019-06-17T18:39:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 15, 2019, 6:39pm UTC](https://discuss.elastic.co/t/inconsistencies-between-dsl-queries-and-java-rest-client/186137/2 "2019-07-15T18:39:28Z")

</div>

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