# Java DSL and Query DSL different results

**URL:** <https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004>\
**Category:** Elasticsearch\
**Created:** [March 4, 2013, 8:21pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004 "2013-03-04T20:21:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric\_sanford](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@eric\_sanford](https://discuss.elastic.co/u/eric_sanford)\
**Post date:** [March 4, 2013, 8:21pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/1 "2013-03-04T20:21:57Z")

</div>

Hello, when i run this query...

{"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, \* "fields" : ["NUM\_OF\_WKS"]\*,  
"facets" :  
{"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}

I corerctly get only the _NUM\_OF\_WKS_ fleld back

but when i set the same query into a java search, i get _null_ for that  
fiels

final SearchResponse response = client.search(new  
SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}},  
\*"fields" : ["NUM\_OF\_WKS"]\*, "facets" :  
{"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"}  
}}}")).actionGet();

Can anyone help with this

thank you !

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 4, 2013, 8:30pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/2 "2013-03-04T20:30:38Z")

</div>

Instead ".source(...)", maybe ".setExtraSource(...)" works...

When I use filters, or size offset, I use extraSource() in  
SearchRequestBuilder()

Jörg

Am 04.03.13 21:21, schrieb eric sanford:

> Hello, when i run this query...
> 
> {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, \* "fields" :  
> ["NUM\_OF\_WKS"]\*, "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> 
> I corerctly get only the _NUM\_OF\_WKS_ fleld back
> 
> but when i set the same query into a java search, i get _null_ for  
> that fiels
> 
> final SearchResponse response = client.search(new  
> SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}},  
> \*"fields" : ["NUM\_OF\_WKS"]\*, "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"}  
> }}}")).actionGet();
> 
> Can anyone help with this
> 
> ## thank you !
> 
> You received this message because you are subscribed to the Google  
> Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send  
> an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [March 4, 2013, 8:35pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/3 "2013-03-04T20:35:05Z")

</div>

Not sure of what happen here but, in Java, I recommend to use helper methods.  
I will probably write your query like this:

```
    SearchResponse response = client.prepareSearch("scnprobldir3a")
            .setTypes("dimItem")
            .addField("NUM_OF_WKS")
            .setFilter(FilterBuilders.existsFilter("NUM_OF_WKS"))
            .addFacet(FacetBuilders.termsFacet("Number_of_Weeks_Facet").field("NUM_OF_WKS").size(100))
            .execute().actionGet();

```

See java API documentation: [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)

Does it help?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 mars 2013 à 21:21, eric sanford [pcstechnologiesinc@gmail.com](mailto:pcstechnologiesinc@gmail.com) a écrit :

> Hello, when i run this query...
> 
> {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> 
> I corerctly get only the NUM\_OF\_WKS fleld back
> 
> but when i set the same query into a java search, i get null for that fiels
> 
> final SearchResponse response = client.search(new SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"} }}}")).actionGet();
> 
> Can anyone help with this
> 
> thank you !
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [March 4, 2013, 8:38pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/4 "2013-03-04T20:38:22Z")

</div>

I just add a note about your filter.  
You should be aware that it's not applied to your facet. So your facet is computed on all documents.

The fact is that when the field NUM\_OF\_WKS does not exist in the document, no computation is done for that document… 😉

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 mars 2013 à 21:35, David Pilato [david@pilato.fr](mailto:david@pilato.fr) a écrit :

> Not sure of what happen here but, in Java, I recommend to use helper methods.  
> I will probably write your query like this:
> 
> ```
> SearchResponse response = client.prepareSearch("scnprobldir3a")
> .setTypes("dimItem")
> .addField("NUM_OF_WKS")
> .setFilter(FilterBuilders.existsFilter("NUM_OF_WKS"))
> .addFacet(FacetBuilders.termsFacet("Number_of_Weeks_Facet").field("NUM_OF_WKS").size(100))
> .execute().actionGet();
> 
> ```
> 
> See java API documentation: [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)
> 
> Does it help?
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 4 mars 2013 à 21:21, eric sanford [pcstechnologiesinc@gmail.com](mailto:pcstechnologiesinc@gmail.com) a écrit :
> 
> > Hello, when i run this query...
> > 
> > {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> > 
> > I corerctly get only the NUM\_OF\_WKS fleld back
> > 
> > but when i set the same query into a java search, i get null for that fiels
> > 
> > final SearchResponse response = client.search(new SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"} }}}")).actionGet();
> > 
> > Can anyone help with this
> > 
> > thank you !
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![eric\_sanford](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@eric\_sanford](https://discuss.elastic.co/u/eric_sanford)\
**Post date:** [March 5, 2013, 6:13pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/5 "2013-03-05T18:13:31Z")

</div>

i still dont understand why it works using query DSL but not with java API

i tried extraSource instead of source and i still get nulls but i get  
values when i run the same query through Soap UI or the browser

On Monday, March 4, 2013 2:38:22 PM UTC-6, David Pilato wrote:

> I just add a note about your filter.  
> You should be aware that it's not applied to your facet. So your facet is  
> computed on all documents.
> 
> The fact is that when the field NUM\_OF\_WKS does not exist in the document,  
> no computation is done for that document… 😉
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 mars 2013 à 21:35, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\>\> a  
> écrit :
> 
> Not sure of what happen here but, in Java, I recommend to use helper  
> methods.  
> I will probably write your query like this:
> 
> ```
> SearchResponse response = client.prepareSearch("scnprobldir3a")
> .setTypes("dimItem")
> .addField("NUM_OF_WKS")
> .setFilter(FilterBuilders.existsFilter("NUM_OF_WKS"))
> 
> ```
> 
> .addFacet(FacetBuilders.termsFacet("Number\_of\_Weeks\_Facet").field("NUM\_OF\_WKS").size(100))  
> .execute().actionGet();
> 
> See java API documentation:  
> [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)
> 
> Does it help?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> \*  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 mars 2013 à 21:21, eric sanford \<[pcstechno...@gmail.com](mailto:pcstechno...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hello, when i run this query...
> 
> {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, \* "fields" : ["NUM\_OF\_WKS"]\*,  
> "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> 
> I corerctly get only the _NUM\_OF\_WKS_ fleld back
> 
> but when i set the same query into a java search, i get _null_ for that  
> fiels
> 
> final SearchResponse response = client.search(new  
> SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}},  
> \*"fields" : ["NUM\_OF\_WKS"]\*, "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"}  
> }}}")).actionGet();
> 
> Can anyone help with this
> 
> thank you !
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![eric\_sanford](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@eric\_sanford](https://discuss.elastic.co/u/eric_sanford)\
**Post date:** [March 5, 2013, 6:28pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/6 "2013-03-05T18:28:57Z")

</div>

ok i get it now 🙂

thanks for your responses, they helped me track down the issue...

when using a query string that does not specify a field, i get the JSON  
data back with hit.sourceAsString()

this is what was null

apparently when it i specify fields the data is available as raw values in  
getFields

yes.. im an ES newbie 🙂

thx again for your responses

On Monday, March 4, 2013 2:38:22 PM UTC-6, David Pilato wrote:

> I just add a note about your filter.  
> You should be aware that it's not applied to your facet. So your facet is  
> computed on all documents.
> 
> The fact is that when the field NUM\_OF\_WKS does not exist in the document,  
> no computation is done for that document… 😉
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 mars 2013 à 21:35, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\>\> a  
> écrit :
> 
> Not sure of what happen here but, in Java, I recommend to use helper  
> methods.  
> I will probably write your query like this:
> 
> ```
> SearchResponse response = client.prepareSearch("scnprobldir3a")
> .setTypes("dimItem")
> .addField("NUM_OF_WKS")
> .setFilter(FilterBuilders.existsFilter("NUM_OF_WKS"))
> 
> ```
> 
> .addFacet(FacetBuilders.termsFacet("Number\_of\_Weeks\_Facet").field("NUM\_OF\_WKS").size(100))  
> .execute().actionGet();
> 
> See java API documentation:  
> [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)
> 
> Does it help?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> \*  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 mars 2013 à 21:21, eric sanford \<[pcstechno...@gmail.com](mailto:pcstechno...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hello, when i run this query...
> 
> {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, \* "fields" : ["NUM\_OF\_WKS"]\*,  
> "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> 
> I corerctly get only the _NUM\_OF\_WKS_ fleld back
> 
> but when i set the same query into a java search, i get _null_ for that  
> fiels
> 
> final SearchResponse response = client.search(new  
> SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}},  
> \*"fields" : ["NUM\_OF\_WKS"]\*, "facets" :  
> {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"}  
> }}}")).actionGet();
> 
> Can anyone help with this
> 
> thank you !
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [March 8, 2013, 1:55pm UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/7 "2013-03-08T13:55:45Z")

</div>

I think you can ask for field \_source if you need it.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 mars 2013 à 19:28, eric sanford [pcstechnologiesinc@gmail.com](mailto:pcstechnologiesinc@gmail.com) a écrit :

> ok i get it now 🙂
> 
> thanks for your responses, they helped me track down the issue...
> 
> when using a query string that does not specify a field, i get the JSON data back with hit.sourceAsString()
> 
> this is what was null
> 
> apparently when it i specify fields the data is available as raw values in getFields
> 
> yes.. im an ES newbie 🙂
> 
> thx again for your responses
> 
> On Monday, March 4, 2013 2:38:22 PM UTC-6, David Pilato wrote:
> 
> > I just add a note about your filter.  
> > You should be aware that it's not applied to your facet. So your facet is computed on all documents.
> > 
> > The fact is that when the field NUM\_OF\_WKS does not exist in the document, no computation is done for that document… 😉
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 4 mars 2013 à 21:35, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) a écrit :
> > 
> > > Not sure of what happen here but, in Java, I recommend to use helper methods.  
> > > I will probably write your query like this:
> > > 
> > > ```
> > > SearchResponse response = client.prepareSearch("scnprobldir3a")
> > > .setTypes("dimItem")
> > > .addField("NUM_OF_WKS")
> > > .setFilter(FilterBuilders.existsFilter("NUM_OF_WKS"))
> > > .addFacet(FacetBuilders.termsFacet("Number_of_Weeks_Facet").field("NUM_OF_WKS").size(100))
> > > .execute().actionGet();
> > > 
> > > ```
> > > 
> > > See java API documentation: [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)
> > > 
> > > Does it help?
> > > 
> > > --  
> > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > @dadoonet | @elasticsearchfr | @scrutmydocs
> > > 
> > > Le 4 mars 2013 à 21:21, eric sanford [pcstechno...@gmail.com](mailto:pcstechno...@gmail.com) a écrit :
> > > 
> > > > Hello, when i run this query...
> > > > 
> > > > {"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"1"} }}}
> > > > 
> > > > I corerctly get only the NUM\_OF\_WKS fleld back
> > > > 
> > > > but when i set the same query into a java search, i get null for that fiels
> > > > 
> > > > final SearchResponse response = client.search(new SearchRequest("scnprobldir3a").types("dimItem").source("{"filter":{"exists":{"field":"NUM\_OF\_WKS"}}, "fields" : ["NUM\_OF\_WKS"], "facets" : {"Number\_of\_Weeks\_Facet":{"terms":{"field":"NUM\_OF\_WKS","size":"100"} }}}")).actionGet();
> > > > 
> > > > Can anyone help with this
> > > > 
> > > > thank you !
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:47am UTC](https://discuss.elastic.co/t/java-dsl-and-query-dsl-different-results/11004/8 "2017-07-06T02:47:32Z")

</div>


