# Javascript query builder?

**URL:** <https://discuss.elastic.co/t/javascript-query-builder/3532>\
**Category:** Elasticsearch\
**Created:** [November 8, 2010, 2:14am UTC](https://discuss.elastic.co/t/javascript-query-builder/3532 "2010-11-08T02:14:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer\_doron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomer_doron/32/3304_2.png) [@tomer\_doron](https://discuss.elastic.co/u/tomer_doron)\
**Post date:** [November 8, 2010, 2:14am UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/1 "2010-11-08T02:14:21Z")

</div>

to implement something like google's "advanced" search page i thought  
it would make sense to use a client side javascript query builder  
(i.e. create the json query on the client side using javascript).

anyone knows such (i could not ind one)? or is this a wrong approach  
and using the query string query is a better idea? maybe another way  
of achieving this?

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [November 8, 2010, 8:04am UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/2 "2010-11-08T08:04:36Z")

</div>

Hi,

as far as I know there is no json query builder for Javascript yet that  
would provide what you are looking for. However, I think it makes sense to  
have something like that implemented. I haven't made any public announcement  
yet but I am working on Elastic Search javascript client. The code can be  
found here: [GitHub - lukas-vlcek/elasticsearch-js: ElasticSearch Javascript client](https://github.com/lukas-vlcek/elasticsearch-js) It is still a  
work in progress but it already covers whole REST API and query builder  
would make for a nice addition. Do you want to open a ticket? (or contribute  
directly?)

In case you want to see some example of how this javascript client can be  
used check demo folder:  
demo.js[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js)shows  
how to call wrapping methods for REST API (is used from demo.html)  
query.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html)shows  
how you can execute any adhoc request  
simple.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html)is  
so simple that it does not need any explanation at all I think 🙂

Though I think it is pretty simple to work with JSON in javascript (even  
when creating it manually) the query builder would definitely make sense.

Note: the name of the project and its repository location may be subject of  
change in the future. However, I would drop a note into ES mail list in such  
case.

Regards,  
Lukas

On Mon, Nov 8, 2010 at 3:14 AM, tomer doron [tomer.doron@gmail.com](mailto:tomer.doron@gmail.com) wrote:

> to implement something like google's "advanced" search page i thought  
> it would make sense to use a client side javascript query builder  
> (i.e. create the json query on the client side using javascript).
> 
> anyone knows such (i could not ind one)? or is this a wrong approach  
> and using the query string query is a better idea? maybe another way  
> of achieving this?

---

<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:** [November 8, 2010, 3:45pm UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/3 "2010-11-08T15:45:57Z")

</div>

Lukas,

FWIW, we use ES from Javascript for the past 6 months on our project. Let me  
know if I can help in any way.

Some differences are that we use RingoJS, and it is based on Rhino, so we  
can call the Java API directly. This makes our JS implementation very  
simple. Here is our entire search implementation.

/\*\*

- Performs a query against the Elastic Search indices.
- 
- @param json Query object in json form
- @param types Optional fields that allow specific types
- 

```
         to be searched. Use a String comprised of

```

- 

```
         type names separated with a comma. (i.e.

```

- 

```
         "profiles,providers,ventures"). An array

```

- 

```
         of strings can also be used.

```

\*/  
function search(json, types) {  
if (typeof types === 'undefined') types = null;  
if (typeof types === 'string') types = types.split(',');

if (!json.size) json.size = 100;

var source = JSON.stringify(json);

var request = searchRequest(IndexThreadLocal.index).source(source);  
if (types != null) request = request.types(types);

var searchResponse = getClient().search(request).actionGet();  
var searchHits = searchResponse.hits().hits();

return searchHits.map(function(hit) {  
return JSON.parse(hit.sourceAsString());  
});  
}

On Mon, Nov 8, 2010 at 3:04 AM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Hi,
> 
> as far as I know there is no json query builder for Javascript yet that  
> would provide what you are looking for. However, I think it makes sense to  
> have something like that implemented. I haven't made any public announcement  
> yet but I am working on Elastic Search javascript client. The code can be  
> found here: [GitHub - lukas-vlcek/elasticsearch-js: ElasticSearch Javascript client](https://github.com/lukas-vlcek/elasticsearch-js) It is still a  
> work in progress but it already covers whole REST API and query builder  
> would make for a nice addition. Do you want to open a ticket? (or contribute  
> directly?)
> 
> In case you want to see some example of how this javascript client can be  
> used check demo folder:  
> demo.js[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js)shows how to call wrapping methods for REST API (is used from demo.html)  
> query.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html)shows how you can execute any adhoc request  
> simple.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html)is so simple that it does not need any explanation at all I think 🙂
> 
> Though I think it is pretty simple to work with JSON in javascript (even  
> when creating it manually) the query builder would definitely make sense.
> 
> Note: the name of the project and its repository location may be subject of  
> change in the future. However, I would drop a note into ES mail list in such  
> case.
> 
> Regards,  
> Lukas
> 
> On Mon, Nov 8, 2010 at 3:14 AM, tomer doron [tomer.doron@gmail.com](mailto:tomer.doron@gmail.com) wrote:
> 
> > to implement something like google's "advanced" search page i thought  
> > it would make sense to use a client side javascript query builder  
> > (i.e. create the json query on the client side using javascript).
> > 
> > anyone knows such (i could not ind one)? or is this a wrong approach  
> > and using the query string query is a better idea? maybe another way  
> > of achieving this?

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [November 8, 2010, 5:42pm UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/4 "2010-11-08T17:42:26Z")

</div>

Hi James,

that's pretty interesting integration!

My primary goal is to provide useful javascript library to allow easy AJAX  
style development on the web browser side. As you can see the code consists  
of general elasticsearch.js (this should be pure Javascript) and currently  
one wrapper for jQuery. But there is a room for other wrappers (like for  
NodeJS for example).

I haven't been using Ringo so far but it seems that due to its close  
integration with Java (it runs inside JMV) there is actually no need for any  
extra glue code at all as the javascript can call directly all ES native  
Java APIs 🙂 That is nice. So the question is if people using Ringo on the  
backend side need any extra javascript client or not. What is your opinion  
on this? Do you see any overlap with what I do that would be worth  
generalization?

Regards,  
Lukas

On Mon, Nov 8, 2010 at 4:45 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> Lukas,
> 
> FWIW, we use ES from Javascript for the past 6 months on our project. Let  
> me know if I can help in any way.
> 
> Some differences are that we use RingoJS, and it is based on Rhino, so we  
> can call the Java API directly. This makes our JS implementation very  
> simple. Here is our entire search implementation.
> 
> /\*\*
> 
> - Performs a query against the Elastic Search indices.
> - 
> - @param json Query object in json form
> - @param types Optional fields that allow specific types
> - 
> 
> ```
> to be searched. Use a String comprised of
> 
> ```
> 
> - 
> 
> ```
> type names separated with a comma. (i.e.
> 
> ```
> 
> - 
> 
> ```
> "profiles,providers,ventures"). An array
> 
> ```
> 
> - 
> 
> ```
> of strings can also be used.
> 
> ```
> 
> \*/  
> function search(json, types) {  
> if (typeof types === 'undefined') types = null;  
> if (typeof types === 'string') types = types.split(',');
> 
> if (!json.size) json.size = 100;
> 
> var source = JSON.stringify(json);
> 
> var request = searchRequest(IndexThreadLocal.index).source(source);  
> if (types != null) request = request.types(types);
> 
> var searchResponse = getClient().search(request).actionGet();  
> var searchHits = searchResponse.hits().hits();
> 
> return searchHits.map(function(hit) {  
> return JSON.parse(hit.sourceAsString());  
> });  
> }
> 
> On Mon, Nov 8, 2010 at 3:04 AM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:
> 
> > Hi,
> > 
> > as far as I know there is no json query builder for Javascript yet that  
> > would provide what you are looking for. However, I think it makes sense to  
> > have something like that implemented. I haven't made any public announcement  
> > yet but I am working on Elastic Search javascript client. The code can be  
> > found here: [GitHub - lukas-vlcek/elasticsearch-js: ElasticSearch Javascript client](https://github.com/lukas-vlcek/elasticsearch-js) It is still a  
> > work in progress but it already covers whole REST API and query builder  
> > would make for a nice addition. Do you want to open a ticket? (or contribute  
> > directly?)
> > 
> > In case you want to see some example of how this javascript client can be  
> > used check demo folder:  
> > demo.js[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js)shows how to call wrapping methods for REST API (is used from demo.html)  
> > query.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html)shows how you can execute any adhoc request  
> > simple.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html)is so simple that it does not need any explanation at all I think 🙂
> > 
> > Though I think it is pretty simple to work with JSON in javascript (even  
> > when creating it manually) the query builder would definitely make sense.
> > 
> > Note: the name of the project and its repository location may be subject  
> > of change in the future. However, I would drop a note into ES mail list in  
> > such case.
> > 
> > Regards,  
> > Lukas
> > 
> > On Mon, Nov 8, 2010 at 3:14 AM, tomer doron [tomer.doron@gmail.com](mailto:tomer.doron@gmail.com)wrote:
> > 
> > > to implement something like google's "advanced" search page i thought  
> > > it would make sense to use a client side javascript query builder  
> > > (i.e. create the json query on the client side using javascript).
> > > 
> > > anyone knows such (i could not ind one)? or is this a wrong approach  
> > > and using the query string query is a better idea? maybe another way  
> > > of achieving this?

---

<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:** [November 8, 2010, 10:01pm UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/5 "2010-11-08T22:01:32Z")

</div>

Hi Lukas,

Given a choice between a JS facade to a Java library, and a pure JS  
implementation, I would probably opt for the JS/Java solution mostly for  
performance reasons I think.

Of course, if I wanted my library to run on the most extensive set of SSJS  
implementations, I would take the pure JS solution.

That said, I don't think many people are using SSJS outside of small one-off  
websites unless they build on the JVM. I may be naive of the ecosystem at  
large, but I don't see how a systems architect for a critical web presence  
would opt to build out there infrastructure on NodeJS or Narwhal. I could  
never make that decision because I still want to leverage Maven, Spring,  
Spring Security and the numerous Java libraries that exist.

It will be interesting to see how this plays out!

\*Jim Cook  
\*  
[jcook@tracermedia.com](mailto:jcook@tracermedia.com)

_tracermedia interactive [http://www.tracermedia.com/](http://www.tracermedia.com/)_  
780 King Ave. #106  
Columbus, OH 43212

phone: (614) 298-0774  
fax: (614) 298-0776  
cell: (234) 738-2492

[image: vcard-16x16.png] [http://h2vx.com/vcf/blog.visualxs.com](http://h2vx.com/vcf/blog.visualxs.com) [image:  
google.png] [http://www.google.com/profiles/djamescook](http://www.google.com/profiles/djamescook) [image:  
facebook.png] [http://www.facebook.com/people/James-Cook/787873454](http://www.facebook.com/people/James-Cook/787873454) [image:  
icon\_msn.gif] [http://cid-8a84560abdc2d172.profile.live.com/](http://cid-8a84560abdc2d172.profile.live.com/) [image:  
twitter\_16.png] [http://twitter.com/oravecz](http://twitter.com/oravecz) [image:  
skype-smalllogo.gif]callto://koravecz  
[image: linkedin.png] [http://www.linkedin.com/in/javatech](http://www.linkedin.com/in/javatech)

On Mon, Nov 8, 2010 at 12:42 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Hi James,
> 
> that's pretty interesting integration!
> 
> My primary goal is to provide useful javascript library to allow easy AJAX  
> style development on the web browser side. As you can see the code consists  
> of general elasticsearch.js (this should be pure Javascript) and currently  
> one wrapper for jQuery. But there is a room for other wrappers (like for  
> NodeJS for example).
> 
> I haven't been using Ringo so far but it seems that due to its close  
> integration with Java (it runs inside JMV) there is actually no need for any  
> extra glue code at all as the javascript can call directly all ES native  
> Java APIs 🙂 That is nice. So the question is if people using Ringo on the  
> backend side need any extra javascript client or not. What is your opinion  
> on this? Do you see any overlap with what I do that would be worth  
> generalization?
> 
> Regards,  
> Lukas
> 
> On Mon, Nov 8, 2010 at 4:45 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > Lukas,
> > 
> > FWIW, we use ES from Javascript for the past 6 months on our project. Let  
> > me know if I can help in any way.
> > 
> > Some differences are that we use RingoJS, and it is based on Rhino, so we  
> > can call the Java API directly. This makes our JS implementation very  
> > simple. Here is our entire search implementation.
> > 
> > /\*\*
> > 
> > - Performs a query against the Elastic Search indices.
> > - 
> > - @param json Query object in json form
> > - @param types Optional fields that allow specific types
> > - 
> > 
> > ```
> > to be searched. Use a String comprised of
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > type names separated with a comma. (i.e.
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "profiles,providers,ventures"). An array
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > of strings can also be used.
> > 
> > ```
> > 
> > \*/  
> > function search(json, types) {  
> > if (typeof types === 'undefined') types = null;  
> > if (typeof types === 'string') types = types.split(',');
> > 
> > if (!json.size) json.size = 100;
> > 
> > var source = JSON.stringify(json);
> > 
> > var request = searchRequest(IndexThreadLocal.index).source(source);  
> > if (types != null) request = request.types(types);
> > 
> > var searchResponse = getClient().search(request).actionGet();  
> > var searchHits = searchResponse.hits().hits();
> > 
> > return searchHits.map(function(hit) {  
> > return JSON.parse(hit.sourceAsString());  
> > });  
> > }
> > 
> > On Mon, Nov 8, 2010 at 3:04 AM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > as far as I know there is no json query builder for Javascript yet that  
> > > would provide what you are looking for. However, I think it makes sense to  
> > > have something like that implemented. I haven't made any public announcement  
> > > yet but I am working on Elastic Search javascript client. The code can be  
> > > found here: [GitHub - lukas-vlcek/elasticsearch-js: ElasticSearch Javascript client](https://github.com/lukas-vlcek/elasticsearch-js) It is still  
> > > a work in progress but it already covers whole REST API and query builder  
> > > would make for a nice addition. Do you want to open a ticket? (or contribute  
> > > directly?)
> > > 
> > > In case you want to see some example of how this javascript client can be  
> > > used check demo folder:  
> > > demo.js[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js)shows how to call wrapping methods for REST API (is used from demo.html)  
> > > query.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.html)shows how you can execute any adhoc request  
> > > simple.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.html)is so simple that it does not need any explanation at all I think 🙂
> > > 
> > > Though I think it is pretty simple to work with JSON in javascript (even  
> > > when creating it manually) the query builder would definitely make sense.
> > > 
> > > Note: the name of the project and its repository location may be subject  
> > > of change in the future. However, I would drop a note into ES mail list in  
> > > such case.
> > > 
> > > Regards,  
> > > Lukas
> > > 
> > > On Mon, Nov 8, 2010 at 3:14 AM, tomer doron [tomer.doron@gmail.com](mailto:tomer.doron@gmail.com)wrote:
> > > 
> > > > to implement something like google's "advanced" search page i thought  
> > > > it would make sense to use a client side javascript query builder  
> > > > (i.e. create the json query on the client side using javascript).
> > > > 
> > > > anyone knows such (i could not ind one)? or is this a wrong approach  
> > > > and using the query string query is a better idea? maybe another way  
> > > > of achieving this?

---

<div class="post-metadata">

**Author:** ![tomer\_doron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomer_doron/32/3304_2.png) [@tomer\_doron](https://discuss.elastic.co/u/tomer_doron)\
**Post date:** [November 16, 2010, 3:32am UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/6 "2010-11-16T03:32:53Z")

</div>

thanks lukas, this looks interesting. i will probably want to  
contribute directly at some point as the the product i am working on  
matures and will need to make a deeper use of such.

FYI, my front end is based on GWT, so will probably need to build a  
bridge or do a port from pure javascript.

On Nov 8, 12:04 am, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:

> Hi,
> 
> as far as I know there is no json query builder for Javascript yet that  
> would provide what you are looking for. However, I think it makes sense to  
> have something like that implemented. I haven't made any public announcement  
> yet but I am working on Elastic Search javascript client. The code can be  
> found here:[https://github.com/lukas-vlcek/elasticsearch-jsIt](https://github.com/lukas-vlcek/elasticsearch-jsIt) is still a  
> work in progress but it already covers whole REST API and query builder  
> would make for a nice addition. Do you want to open a ticket? (or contribute  
> directly?)
> 
> In case you want to see some example of how this javascript client can be  
> used check demo folder:  
> demo.js[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.js)shows  
> how to call wrapping methods for REST API (is used from demo.html)  
> query.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/quer...](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/quer...)shows  
> how you can execute any adhoc request  
> simple.html[https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simp...](https://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simp...)is  
> so simple that it does not need any explanation at all I think 🙂
> 
> Though I think it is pretty simple to work with JSON in javascript (even  
> when creating it manually) the query builder would definitely make sense.
> 
> Note: the name of the project and its repository location may be subject of  
> change in the future. However, I would drop a note into ES mail list in such  
> case.
> 
> Regards,  
> Lukas
> 
> On Mon, Nov 8, 2010 at 3:14 AM, tomer doron [tomer.do...@gmail.com](mailto:tomer.do...@gmail.com) wrote:
> 
> > to implement something like google's "advanced" search page i thought  
> > it would make sense to use a client side javascript query builder  
> > (i.e. create the json query on the client side using javascript).
> 
> > anyone knows such (i could not ind one)? or is this a wrong approach  
> > and using the query string query is a better idea? maybe another way  
> > of achieving this?

---

<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:16am UTC](https://discuss.elastic.co/t/javascript-query-builder/3532/7 "2017-07-06T04:16:28Z")

</div>


