Javascript query builder?

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?

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 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.jshttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.jsshows
how to call wrapping methods for REST API (is used from demo.html)
query.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.htmlshows
how you can execute any adhoc request
simple.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.htmlis
so simple that it does not need any explanation at all I think :slight_smile:

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 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?

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 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 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.jshttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.jsshows how to call wrapping methods for REST API (is used from demo.html)
query.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.htmlshows how you can execute any adhoc request
simple.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.htmlis so simple that it does not need any explanation at all I think :slight_smile:

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 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?

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 :slight_smile: 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 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 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 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.jshttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.jsshows how to call wrapping methods for REST API (is used from demo.html)
query.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.htmlshows how you can execute any adhoc request
simple.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.htmlis so simple that it does not need any explanation at all I think :slight_smile:

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.comwrote:

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?

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

tracermedia interactive 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 [image:
google.png] http://www.google.com/profiles/djamescook [image:
facebook.png] http://www.facebook.com/people/James-Cook/787873454 [image:
icon_msn.gif] http://cid-8a84560abdc2d172.profile.live.com/ [image:
twitter_16.png] http://twitter.com/oravecz [image:
skype-smalllogo.gif]callto://koravecz
[image: linkedin.png] http://www.linkedin.com/in/javatech

On Mon, Nov 8, 2010 at 12:42 PM, Lukáš Vlček 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 :slight_smile: 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 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.comwrote:

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 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.jshttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.jsshows how to call wrapping methods for REST API (is used from demo.html)
query.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/query.htmlshows how you can execute any adhoc request
simple.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simple.htmlis so simple that it does not need any explanation at all I think :slight_smile:

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.comwrote:

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?

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 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 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.jshttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/demo.jsshows
how to call wrapping methods for REST API (is used from demo.html)
query.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/quer...shows
how you can execute any adhoc request
simple.htmlhttps://github.com/lukas-vlcek/elasticsearch-js/blob/master/demo/simp...is
so simple that it does not need any explanation at all I think :slight_smile:

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 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?