# Learning the Query DSL

**URL:** <https://discuss.elastic.co/t/learning-the-query-dsl/3091>\
**Category:** Elasticsearch\
**Created:** [July 12, 2010, 7:57pm UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091 "2010-07-12T19:57:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [July 12, 2010, 7:57pm UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/1 "2010-07-12T19:57:21Z")

</div>

The documentation is a bit sparse on describing the query capabilities. Is  
there a recommended online source to get familiar with Elastic Search's  
syntax and terminology? Would looking into Lucene resources help?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 12, 2010, 8:22pm UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/2 "2010-07-12T20:22:53Z")

</div>

Can you give some examples as to what you are missing? Is that how query  
behave, or maybe how to construct them (using JSON for example)?

On Mon, Jul 12, 2010 at 10:57 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> The documentation is a bit sparse on describing the query capabilities. Is  
> there a recommended online source to get familiar with Elastic Search's  
> syntax and terminology? Would looking into Lucene resources help?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [July 13, 2010, 3:32am UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/3 "2010-07-13T03:32:37Z")

</div>

There is just the terminology hurdles which I have been able to get  
over using the Lucene documentation (diff between term and field, what  
is boost, etc..).

But I would appreciate an example that shows how to query an index  
when presented with a JSON object, but from the Java API.

Thanks.

On Jul 12, 4:22 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Can you give some examples as to what you are missing? Is that how query  
> behave, or maybe how to construct them (using JSON for example)?
> 
> On Mon, Jul 12, 2010 at 10:57 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com) wrote:
> 
> > The documentation is a bit sparse on describing the query capabilities. Is  
> > there a recommended online source to get familiar with Elastic Search's  
> > syntax and terminology? Would looking into Lucene resources help?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [July 13, 2010, 4:55am UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/4 "2010-07-13T04:55:39Z")

</div>

That should read:

"But I would appreciate an example that shows how to query an index  
when presented with a JSON String, but from the Java API."

I have tried:  
var source = JSON.stringify(json);  
source = searchSource().query(new  
QueryStringQueryBuilder(source)).buildAsBytes();  
var request = searchRequest(index).types(types).source(source);  
var response = getClient().search(request).actionGet();

But I get these parser exceptions:  
00:53:45,455 ERROR 47115-26 rest: ? -  
Error while processing request: /api/test/hazel, error: JavaException:  
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
execute [query] total failure; shardFailures {null:  
RemoteTransportException[[Antonio][inet[/127.0.0.1:9310]][search/phase/query]];  
nested:  
NotSerializableTransportException[[org.elasticsearch.search.SearchParseException]  
[nep][4]: query[null],from[-1],size[-1]: Parse Failure [Failed to parse  
[{"query":{"query\_string":{"query":"{"field":{"patient.lastname":"Cook"}}"}}}]];  
[nep] Failed to parse query [{"field":{"patient.lastname":"Cook"}}]; Cannot  
parse '{"field":{"patient.lastname":"Cook"}}': Encountered " "}" "} "" at  
line 1, column 35.  
Was expecting one of:  
"TO" ...  
\<RANGEEX\_QUOTED\> ...  
\<RANGEEX\_GOOP\> ...  
; Encountered " "}" "} "" at line 1, column 35.  
Was expecting one of:  
"TO" ...  
\<RANGEEX\_QUOTED\> ...  
\<RANGEEX\_GOOP\> ...

On Mon, Jul 12, 2010 at 11:32 PM, oravecz [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> There is just the terminology hurdles which I have been able to get  
> over using the Lucene documentation (diff between term and field, what  
> is boost, etc..).
> 
> But I would appreciate an example that shows how to query an index  
> when presented with a JSON object, but from the Java API.
> 
> Thanks.
> 
> On Jul 12, 4:22 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Can you give some examples as to what you are missing? Is that how query  
> > behave, or maybe how to construct them (using JSON for example)?
> > 
> > On Mon, Jul 12, 2010 at 10:57 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com)  
> > wrote:
> > 
> > > The documentation is a bit sparse on describing the query capabilities.  
> > > Is  
> > > there a recommended online source to get familiar with Elastic Search's  
> > > syntax and terminology? Would looking into Lucene resources help?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 13, 2010, 7:21am UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/5 "2010-07-13T07:21:35Z")

</div>

If you have the full search request represented as JSON (with the "query"  
top level element), then just pass that json (as string or bytes) to  
SearchRequest#source(...).

-shay.banon

On Tue, Jul 13, 2010 at 7:55 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> That should read:
> 
> "But I would appreciate an example that shows how to query an index  
> when presented with a JSON String, but from the Java API."
> 
> I have tried:  
> var source = JSON.stringify(json);  
> source = searchSource().query(new  
> QueryStringQueryBuilder(source)).buildAsBytes();  
> var request = searchRequest(index).types(types).source(source);  
> var response = getClient().search(request).actionGet();
> 
> But I get these parser exceptions:  
> 00:53:45,455 ERROR 47115-26 rest: ? -  
> Error while processing request: /api/test/hazel, error: JavaException:  
> org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
> execute [query] total failure; shardFailures {null:  
> RemoteTransportException[[Antonio][inet[/127.0.0.1:9310]][search/phase/query]];  
> nested:  
> NotSerializableTransportException[[org.elasticsearch.search.SearchParseException]  
> [nep][4]: query[null],from[-1],size[-1]: Parse Failure [Failed to parse  
> [{"query":{"query\_string":{"query":"{"field":{"patient.lastname":"Cook"}}"}}}]];  
> [nep] Failed to parse query [{"field":{"patient.lastname":"Cook"}}]; Cannot  
> parse '{"field":{"patient.lastname":"Cook"}}': Encountered " "}" "} "" at  
> line 1, column 35.  
> Was expecting one of:  
> "TO" ...  
> \<RANGEEX\_QUOTED\> ...  
> \<RANGEEX\_GOOP\> ...  
> ; Encountered " "}" "} "" at line 1, column 35.  
> Was expecting one of:  
> "TO" ...  
> \<RANGEEX\_QUOTED\> ...  
> \<RANGEEX\_GOOP\> ...
> 
> On Mon, Jul 12, 2010 at 11:32 PM, oravecz [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > There is just the terminology hurdles which I have been able to get  
> > over using the Lucene documentation (diff between term and field, what  
> > is boost, etc..).
> > 
> > But I would appreciate an example that shows how to query an index  
> > when presented with a JSON object, but from the Java API.
> > 
> > Thanks.
> > 
> > On Jul 12, 4:22 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Can you give some examples as to what you are missing? Is that how query  
> > > behave, or maybe how to construct them (using JSON for example)?
> > > 
> > > On Mon, Jul 12, 2010 at 10:57 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com)  
> > > wrote:
> > > 
> > > > The documentation is a bit sparse on describing the query  
> > > > capabilities. Is  
> > > > there a recommended online source to get familiar with Elastic  
> > > > Search's  
> > > > syntax and terminology? Would looking into Lucene resources help?

---

<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, 4:22am UTC](https://discuss.elastic.co/t/learning-the-query-dsl/3091/6 "2017-07-06T04:22:24Z")

</div>


