Last active
October 1, 2015 01:27
-
-
Save egaumer/1893930 to your computer and use it in GitHub Desktop.
Example boolQuery using Cloud9 Javascript API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* fullscale.examples.elasticjs */ | |
(function($) { | |
/* compose a BoolQuery out of several TermQuery objs */ | |
var boolQuery = evo.BoolQuery() | |
.must( | |
evo.TermQuery("message", "hello")) | |
.mustNot( | |
evo.TermQuery("message", "back")) | |
.should( | |
evo.TermQuery("user", "jsmith")); | |
/* a function to display results - uses underscore.js templates */ | |
var resultsCallBack = function(results) { | |
if (results.hits) { | |
var template = _.template($("#results").html(), results.hits); | |
$(".search").empty(); | |
$(".search").append(template); | |
} | |
}; | |
/* execute the request */ | |
evo.Request() | |
.indices("twitter") | |
.types("tweet") | |
.query(boolQuery) | |
.doSearch(resultsCallBack); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<head> | |
<title>Simple Search</title> | |
<!-- Example search template using underscore.js --> | |
<script type="text/template" id="results"> | |
<% _.each(hits, function(hit) { %> | |
<li><%= hit._source.message %></li> | |
<% }); %> | |
</script> | |
</head> | |
<body> | |
<div class="search"></div> | |
<script src="js/jquery-1.6.2.min.js"></script> | |
<script src="js/underscore-min.js"></script> | |
<script src="js/c9/c9api.min.js"></script> | |
<!-- change 'yourapp' to the name of your Cloud9 application --> | |
<script defer src="yourapp/js/boolSearch.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/1' -d '{ | |
"user": "jsmith", | |
"date": "2012-03-02", | |
"message": "A simple message saying hello" | |
}' | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/2' -d '{ | |
"user": "jsmith", | |
"date": "2012-03-03", | |
"message": "A simple message saying goodbye" | |
}' | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/3' -d '{ | |
"user": "jdoe", | |
"date": "2012-03-02", | |
"message": "A simple message saying hello back" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although Lucene provides the ability to create your own queries through its API, it also provides a rich query language through the Query Parser, a lexer which interprets a string into a Lucene Query.
For detailed information of that syntax see the Lucene Query Parser Syntax
Cloud9 exposes this query syntax through its queryString object which provides an easier mechanism for writing more complex queries.
An example of that can be seen here - https://gist.github.com/1893397