elastic.js
A JavaScript implementation of the elasticsearch Query DSL
elastic.js: Namespace: ejs
I made elastic.js build dynamic query like this:
{
"size": 15,
"query": {
"bool": {
"must": [
{ "term": { "tag": { "term": "rocket" } } },
{ "term": { "name": { "term": "space" } } }
],
"should": [
{ "wildcard": { "place": { "value": "Moo*" } } }
]
}
}
}
Elastic.js code for this is ( Translator ):
ejs.Request()
.size(15)
.query(
ejs.BoolQuery()
.must(ejs.TermQuery('tag', 'rocket'))
.must(ejs.TermQuery('name', 'space'))
.should(ejs.WildcardQuery('place', 'Moo*'))
)
It works great, I am happy and I would like it to be like that. But I realized that I need to add an option to perform this query with OR
condition, instead of AND
as is now.
It should find documents that match any of provided conditions.
And that task leaves me with no clues (even about DSL that will complete this purpose).
I have looked at OrFilter but I have no idea on how to use it right (especially with elasticJS). Any solid source of information on elastic/js will be greatly appreciated
Source: (StackOverflow)
i am currently using Elastic.js (Angular.js integration) to query Elasticsearch.
I have an Elasticsearch query that is as follows:
{
"query" : {
"range" : {
"created_at" : {
"from" : "2013-07-21T03:55:32.000"
}
}
}, "facets" : {
"tag" : {
"terms" : {
"field" : "hashtag.text",
"size" : 10
}
}
}
}
I have a query that works without the data range filter, the query using Angular and Elastic.js is :
.query(ejs.QueryStringQuery($rootScope.globalVariable || '*'))
.facet(
ejs.TermsFacet('tags')
.field('hashtag.text')
.size(50))
.doSearch();
I have tried many combinations to add the date range filter to the Elastic.js query.
Can anyone please give some ideas/clues on how I can do this?
Many thanks
Source: (StackOverflow)
I have this code:
$scope.search = function() {
$scope.results = ejs.Request()
.query(ejs.TermQuery("amount", 10)).size(10).from(0)
.doSearch();
console.log($scope.results.v);
};
and :
<tr id="tr" ng-repeat="record in results.hits.hits" repeat-done="reload_scroll()">
<td><input type="checkbox" ng-model="record._source.checked"/></td>
<td>{{ record._source.id }}</td>
</tr>
and it work properly. But I want to have access to $scope.results in js code but when I write:
$scope.search = function() {
$scope.results = ejs.Request()
.query(ejs.TermQuery("amount", 10)).size(10).from(0)
.doSearch();
console.log($scope.results.$$v);
};
but it print undefined it console, what should I use instead $$v?
Thanks.
Source: (StackOverflow)
As seen on the official documentation of FullScale, I've got :
// The official one
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: conf.elastic.server
});
// FullScale one (for some reasons, needing the official one, whereas in AngularJS, same version, used alone. But hey ! I'm not judging.
var ejs = require('elastic.js');
client.search({
index: conf.elastic.indice,
type: conf.elastic.index,
body: ejs.Request().query(ejs.BoolQuery().must(ejs.MatchQuery('field': 'exemple'))
}).then(function(resp) {
_this.sendResponse(null, resp.hits.hits, res);
}, function(args) {
console.trace("Erreur #" + args.status + " : " + args.error);
});
And everything seems to work, except when I look closely to the results that have absolutely nothing to do with 'exemple', like :
{
"field": "something that have absolutely nothing to do with anything"
},
{
"field": "lolwut i don't even know how to elasticsearch"
},
{
"field": "kthxbye"
}
Is the elastic.js (fullscale) broken on npm (because I know it's working on AngularJS) ?
or have I forgot to guess something that wasn't in the FullScale documentation ?
Thanks.
Source: (StackOverflow)
Long story short.
I need to create an analogue with elasticjs for query:
http://example.com/one/two/_search?q=tags:three*
I'm confused with options listed on the docs page. Already tried to create BoolQuery
, TermQuery
and a couple of others, but they don't work for me.
I'm stuck now and would appreciate any kind of help on subject.
P.S. And another side of the same question. I can't find how json should look to obtain the same data. Came up with this solution so far, but unfortunately it's not working:
{
"query": {
"bool": {
"should": [
{
"term": {
"tag": "three*"
}
}
]
}
}
}
Source: (StackOverflow)
Is there a way to cancel requests/queries to Elasticsearch using elasticjs? The web app I am working on performs a request/query every 5 seconds, but I would like to cancel the request if for some reason the response doesn't show up in 5 seconds (so the browser doesn't pile up a bunch of requests that are unnecessary since the queries are happening repeatedly). I understand this would not prevent Elasticsearch from completing the query, but I would like to at least cancel the request in the browser.
Example:
var request = ejs.Request().doSearch();
var dataFromElasticsearch;
request.then(function (data) {
dataFromElasticsearch = data;
});
setTimeout(function () {
if (!dataFromElasticsearch) {
//do something here to cancel request
}
}, 5000)
Source: (StackOverflow)
I'm building a leaderboard with elasticsearch. I'd like to query all documents who have points greater than a given amount using the following query:
{
"constant_score" : {
"filter" : {
"range" : {
"totalPoints" : {
"gt": 242
}
}
}
}
This works perfectly -- elasticsearch appropriately returns all documents with points greater than 242. However, all I really need is the count of elements matching this query. Since I'm sending the result over the network, it would be helpful if the query simply returned the count, as opposed to all of the documents matching the filter.
How do I get elasticsearch to only report the count of documents matching the filter?
EDIT: I've learned that what I'm looking for is setting search_type
to count
. However, I'm not sure how to do this with elastic.js. Any noders willing to pitch in their advice?
Source: (StackOverflow)