# Different result between java client api and query dsl?

**URL:** <https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216>\
**Category:** Elasticsearch\
**Created:** [May 10, 2017, 9:29am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216 "2017-05-10T09:29:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anzhilin](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anzhilin](https://discuss.elastic.co/u/anzhilin)\
**Post date:** [May 10, 2017, 9:29am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216/1 "2017-05-10T09:29:06Z")

</div>

i am using the 2.3.5 version elasticsearch ,this is the whole data:

==================================

```auto
{
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdNN3mqK8n_bRen0r",
"_score": 1,
"_source": {
"age": 325,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdOE-mqK8n_bRen0s",
"_score": 1,
"_source": {
"age": 335,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdMdjmqK8n_bRen0q",
"_score": 1,
"_source": {
"age": 35,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdJXLmqK8n_bRen0p",
"_score": 1,
"_source": {
"age": 25,
"about": "gasdf ghasd"
}
}
]
}
}

```

====================  
when i am using java client api for searching:

```
    QueryBuilder qb = QueryBuilders.termQuery("age","25");
    SearchRequestBuilder builder = client.prepareSearch("testindex");
    SearchResponse res = builder.setTypes("testtype").setQuery(qb).execute().actionGet();
    SearchHits hits = res.getHits();

```

# it returns only one hit that the age equal 25

but when i am using query dsl in head plugin:

{"query":{"term":{"age":"25"}}}

it returned all the document

```auto
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdNN3mqK8n_bRen0r",
"_score": 1,
"_source": {
"age": 325,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdOE-mqK8n_bRen0s",
"_score": 1,
"_source": {
"age": 335,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdMdjmqK8n_bRen0q",
"_score": 1,
"_source": {
"age": 35,
"about": "gasdf ghasd"
}
}
,
{
"_index": "testindex",
"_type": "testtype",
"_id": "AVvxdJXLmqK8n_bRen0p",
"_score": 1,
"_source": {
"age": 25,
"about": "gasdf ghasd"
}
}
]
}

```

am i using the wrong api??thx buddy

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 10, 2017, 10:14am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216/2 "2017-05-10T10:14:11Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

Probably a bug with HEAD plugin as it does not support GET with body.  
Try with POST or use Kibana Dev Console.

---

<div class="post-metadata">

**Author:** ![anzhilin](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anzhilin](https://discuss.elastic.co/u/anzhilin)\
**Post date:** [May 10, 2017, 10:43am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216/3 "2017-05-10T10:43:23Z")

</div>

thanks, i will try with POST later

---

<div class="post-metadata">

**Author:** ![anzhilin](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anzhilin](https://discuss.elastic.co/u/anzhilin)\
**Post date:** [May 10, 2017, 10:48am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216/4 "2017-05-10T10:48:53Z")

</div>

thanks again,using POST method got the correct result

---

<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:** [June 7, 2017, 10:52am UTC](https://discuss.elastic.co/t/different-result-between-java-client-api-and-query-dsl/85216/5 "2017-06-07T10:52:59Z")

</div>

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