forked from CryptoBridge/bitshares-es-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.js
More file actions
executable file
·60 lines (47 loc) · 1.51 KB
/
Copy pathwrapper.js
File metadata and controls
executable file
·60 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
const request = require('superagent');
const express = require('express');
var server = express();
server.get( '/get_account_history', (req, response, next) => {
var account_id= req.query.account_id;
var gte = req.query.from_date;
var lte = req.query.to_date;
var sortby = req.query.sort_by;
var size = req.query.size;
if (size > 10000) {
size = 10000;
}
const json = {
"sort": [{"block_data.block_time": {"order": "desc"}}],
"query": {"bool": {"must": [{"match": {"account_history.account":account_id}},
{"range": {"block_data.block_time": {"gte": gte, "lte": lte}}}]}},
"from": 0, "size": size
};
request
.post('http://localhost:9200/_search')
.send(json)
.set('accept', 'json')
.end((err, res) => {
if (err) {
console.error(err);
return response.status(err.status || 500).json(err);
}
if (!res.body || !res.body.hits || !res.body.hits.hits ) {
console.warn('Empty result');
return response.json([]);
}
if (res.body.hits.hits) {
var results = [];
res.body.hits.hits.map((item) => {
results.push(item._source);
});
response.json(results);
}
else {
response.json([]);
}
});
});
server.listen(5000, () => {
console.log('BitShares ES Wrapper is running on port 5000');
});