# Help with "bool" and "prefix" query in url

**URL:** <https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034>\
**Category:** Elasticsearch\
**Created:** [August 2, 2011, 8:38pm UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034 "2011-08-02T20:38:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [August 2, 2011, 8:38pm UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/1 "2011-08-02T20:38:49Z")

</div>

Hi, should a query specified by a "json" body also be able to be sent  
via the url only? E.g. this query works fine:

curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
{must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
"hello"}}]}}}'

but I would like to convert it to a GET with _only_ a url, no body.

I'm looking at [http://www.elasticsearch.org/guide/reference/api/search/uri-request.html](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)  
and can do this query, but don't understand how to specify a "prefix"  
query or how to specify the "bool" (and?) query.

curl -XGET 'localhost:9200/\_search?pretty=yes&q=context:example.com/  
mybucket&q=hello%20world.html'

Thanks,  
Jamshid

---

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [August 4, 2011, 8:45am UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/2 "2011-08-04T08:45:27Z")

</div>

On Aug 2, 3:38 pm, Jamshid [jamshi...@gmail.com](mailto:jamshi...@gmail.com) wrote:

> Hi, should a query specified by a "json" body also be able to be sent  
> via the url only? [...]
> 
> curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
> "hello"}}]}}}'

Oh I'm so close, but it seems like default\_operator doesn't do what I  
think it does.

I want all docs where "context" is "[example.com/mybucket](http://example.com/mybucket)" and "name"  
begins with "var".

This query returns documents matching _either_, even though I specify  
"default\_operator=AND".

curl -i -XGET 'localhost:9200/\_search?  
pretty=yes&default\_operator=AND&q=context:example.com/  
mybucket&q=name:var\*'  
...  
"\_source" : { "mytype" : { "name" : "var/hello.html", "context" :  
"[example.com/mybucket](http://example.com/mybucket)" } }  
"\_source" : { "mytype" : { "name" : "var/hello.html", "context" :  
"[example2.com/mybucket](http://example2.com/mybucket)"} }

I know elasticsearch "sees" "default\_operator", because it complains  
if I give it a garbage value. Any idea what I'm doing wrong?

Actually one thing wrong is that I'm using multiple "q" query args --  
all but the last are ignored.

Thanks,  
Jamshid

---

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [August 4, 2011, 9:03am UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/3 "2011-08-04T09:03:40Z")

</div>

Doh, ok the syntax for url queries is similar to Solr / Lucene syntax.  
To get a url-only query like this:

curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
{must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
"var"}}]}}}'

I need to set the "q" query arg to the url-encoded string  
"context:example.com/mybucket name:var\*", and I need to set the  
default\_operator to AND:

curl -XGET 'localhost:9200/\_search?  
pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
%20name:var\*'

Hope this helps someone else.

Maybe an example like this could be added to  
[http://www.elasticsearch.org/guide/reference/api/search/uri-request.html](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)  
or enable comments and I'll mention it.

Thanks,  
Jamshid

---

<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:** [August 4, 2011, 5:53pm UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/4 "2011-08-04T17:53:10Z")

</div>

Another option is to provide the json body request in the uri, if you  
want... .

On Thu, Aug 4, 2011 at 12:03 PM, Jamshid [jamshid69@gmail.com](mailto:jamshid69@gmail.com) wrote:

> Doh, ok the syntax for url queries is similar to Solr / Lucene syntax.  
> To get a url-only query like this:
> 
> curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
> "var"}}]}}}'
> 
> I need to set the "q" query arg to the url-encoded string  
> "context:example.com/mybucket name:var\*", and I need to set the  
> default\_operator to AND:
> 
> curl -XGET 'localhost:9200/\_search?  
> pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
> %20name:var\*'
> 
> Hope this helps someone else.
> 
> Maybe an example like this could be added to  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)  
> or enable comments and I'll mention it.
> 
> Thanks,  
> Jamshid

---

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [August 9, 2011, 8:31pm UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/5 "2011-08-09T20:31:06Z")

</div>

Sorry not sure what you mean, can an arbitrary json body instead be  
url encoded and used as a query string argument, so that the GET  
request's Content-length is 0?

What is the name of the query string argument?

Thanks,  
Jamshid

On Aug 4, 12:53 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Another option is to provide the json body request in the uri, if you  
> want... .
> 
> On Thu, Aug 4, 2011 at 12:03 PM, Jamshid [jamshi...@gmail.com](mailto:jamshi...@gmail.com) wrote:
> 
> > Doh, ok the syntax for url queries is similar to Solr / Lucene syntax.  
> > To get a url-only query like this:
> 
> > curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> > {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
> > "var"}}]}}}'
> 
> > I need to set the "q" query arg to the url-encoded string  
> > "context:example.com/mybucket name:var\*", and I need to set the  
> > default\_operator to AND:
> 
> > curl -XGET 'localhost:9200/\_search?  
> > pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
> > %20name:var\*'
> 
> > Hope this helps someone else.
> 
> > Maybe an example like this could be added to  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)  
> > or enable comments and I'll mention it.
> 
> > Thanks,  
> > Jamshid

---

<div class="post-metadata">

**Author:** ![jschelle\_2](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jschelle\_2](https://discuss.elastic.co/u/jschelle_2)\
**Post date:** [April 27, 2012, 2:53pm UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/6 "2012-04-27T14:53:41Z")

</div>

Does anyone know the answer to Jamshid's question above? This is the exact  
problem I'm trying to figure out. Putting the JSON body in the URI doesn't  
seem to work with \_percolate. Or maybe I'm not encoding it right?

On Tuesday, August 9, 2011 4:31:06 PM UTC-4, Jamshid wrote:

> Sorry not sure what you mean, can an arbitrary json body instead be  
> url encoded and used as a query string argument, so that the GET  
> request's Content-length is 0?
> 
> What is the name of the query string argument?
> 
> Thanks,  
> Jamshid
> 
> On Aug 4, 12:53 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Another option is to provide the json body request in the uri, if you  
> > want... .
> > 
> > On Thu, Aug 4, 2011 at 12:03 PM, Jamshid [jamshi...@gmail.com](mailto:jamshi...@gmail.com) wrote:
> > 
> > > Doh, ok the syntax for url queries is similar to Solr / Lucene syntax.  
> > > To get a url-only query like this:
> > 
> > > curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> > > {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
> > > "var"}}]}}}'
> > 
> > > I need to set the "q" query arg to the url-encoded string  
> > > "context:example.com/mybucket name:var\*", and I need to set the  
> > > default\_operator to AND:
> > 
> > > curl -XGET 'localhost:9200/\_search?  
> > > pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
> > > %20name:var\*'
> > 
> > > Hope this helps someone else.
> > 
> > > Maybe an example like this could be added to
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)
> 
> > > or enable comments and I'll mention it.
> > 
> > > Thanks,  
> > > Jamshid

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 28, 2012, 4:17am UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/7 "2012-04-28T04:17:29Z")

</div>

It's possible to specify JSON query in the "source" parameter of the  
.../\_search URL. However, there is no such support for .../\_percolate.

On Friday, April 27, 2012 10:53:41 AM UTC-4, jschelle wrote:

> Does anyone know the answer to Jamshid's question above? This is the exact  
> problem I'm trying to figure out. Putting the JSON body in the URI doesn't  
> seem to work with \_percolate. Or maybe I'm not encoding it right?
> 
> On Tuesday, August 9, 2011 4:31:06 PM UTC-4, Jamshid wrote:
> 
> > Sorry not sure what you mean, can an arbitrary json body instead be  
> > url encoded and used as a query string argument, so that the GET  
> > request's Content-length is 0?
> > 
> > What is the name of the query string argument?
> > 
> > Thanks,  
> > Jamshid
> > 
> > On Aug 4, 12:53 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Another option is to provide the json body request in the uri, if you  
> > > want... .
> > > 
> > > On Thu, Aug 4, 2011 at 12:03 PM, Jamshid [jamshi...@gmail.com](mailto:jamshi...@gmail.com) wrote:
> > > 
> > > > Doh, ok the syntax for url queries is similar to Solr / Lucene  
> > > > syntax.  
> > > > To get a url-only query like this:
> > > 
> > > > curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> > > > {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix:  
> > > > {"name":  
> > > > "var"}}]}}}'
> > > 
> > > > I need to set the "q" query arg to the url-encoded string  
> > > > "context:example.com/mybucket name:var\*", and I need to set the  
> > > > default\_operator to AND:
> > > 
> > > > curl -XGET 'localhost:9200/\_search?  
> > > > pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
> > > > %20name:var\*'
> > > 
> > > > Hope this helps someone else.
> > > 
> > > > Maybe an example like this could be added to
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)
> > 
> > > > or enable comments and I'll mention it.
> > > 
> > > > Thanks,  
> > > > Jamshid

---

<div class="post-metadata">

**Author:** ![tfreitas](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tfreitas](https://discuss.elastic.co/u/tfreitas)\
**Post date:** [August 2, 2012, 1:42am UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/8 "2012-08-02T01:42:42Z")

</div>

Hi kimchy, could you provide an example, I do not understand "provide the  
json body in the request uri"

regards

On Thursday, August 4, 2011 1:23:10 PM UTC-4:30, kimchy wrote:

> Another option is to provide the json body request in the uri, if you  
> want... .
> 
> On Thu, Aug 4, 2011 at 12:03 PM, Jamshid [jamshid69@gmail.com](mailto:jamshid69@gmail.com) wrote:
> 
> > Doh, ok the syntax for url queries is similar to Solr / Lucene syntax.  
> > To get a url-only query like this:
> > 
> > curl -XGET 'localhost:9200/\_search?pretty=yes' -d '{query: {bool:  
> > {must: [{term: {"context": "[example.com/mybucket](http://example.com/mybucket)"}},{prefix: {"name":  
> > "var"}}]}}}'
> > 
> > I need to set the "q" query arg to the url-encoded string  
> > "context:example.com/mybucket name:var\*", and I need to set the  
> > default\_operator to AND:
> > 
> > curl -XGET 'localhost:9200/\_search?  
> > pretty=yes&default\_operator=AND&q=context:example.com/mybucket  
> > %20name:var\*'
> > 
> > Hope this helps someone else.
> > 
> > Maybe an example like this could be added to  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/uri-request.html)  
> > or enable comments and I'll mention it.
> > 
> > Thanks,  
> > Jamshid

---

<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, 3:18am UTC](https://discuss.elastic.co/t/help-with-bool-and-prefix-query-in-url/5034/9 "2017-07-06T03:18:03Z")

</div>


