@ocap/indexdb-elasticsearch 1.13.19 → 1.13.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/db.js +17 -5
  2. package/package.json +4 -4
package/lib/db.js CHANGED
@@ -274,7 +274,13 @@ class ESIndexDB extends BaseIndexDB {
274
274
  }
275
275
 
276
276
  async listTopAccounts({ tokenAddress, paging } = {}) {
277
- const pagination = formatPagination({ paging, defaultSortField: 'balance' });
277
+ const filter = { term: { 'tokens.address': tokenAddress } };
278
+ const pagination = formatPagination({
279
+ paging,
280
+ defaultSortField: 'balance',
281
+ supportedSortFields: ['genesisTime', 'renaissanceTime', 'balance'],
282
+ });
283
+
278
284
  let sort = null;
279
285
  if (pagination.order.field === 'balance') {
280
286
  sort = [
@@ -284,9 +290,7 @@ class ESIndexDB extends BaseIndexDB {
284
290
  order: pagination.order.type,
285
291
  nested: {
286
292
  path: 'tokens',
287
- filter: {
288
- term: { 'tokens.address': tokenAddress },
289
- },
293
+ filter,
290
294
  },
291
295
  },
292
296
  },
@@ -306,7 +310,15 @@ class ESIndexDB extends BaseIndexDB {
306
310
  const result = await this.account.search({
307
311
  from: pagination.cursor,
308
312
  size: pagination.size,
309
- body: { query: FALLBACK_QUERY, sort },
313
+ body: {
314
+ query: {
315
+ nested: {
316
+ path: 'tokens',
317
+ query: { bool: { filter } },
318
+ },
319
+ },
320
+ sort,
321
+ },
310
322
  });
311
323
 
312
324
  const { items, paging: nextPaging } = formatQueryResult(result, pagination);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocap/indexdb-elasticsearch",
3
3
  "description": "OCAP indexdb adapter that uses elasticsearch as backend",
4
- "version": "1.13.19",
4
+ "version": "1.13.20",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ArcBlock/asset-chain/issues",
@@ -38,11 +38,11 @@
38
38
  "test": "node tools/jest.js",
39
39
  "coverage": "npm run test -- --coverage"
40
40
  },
41
- "gitHead": "d26ead3520a1a6616f77073f852a8c742101dfa4",
41
+ "gitHead": "fbb1920c30088668db5d015d695fb01416ecefc7",
42
42
  "dependencies": {
43
43
  "@elastic/elasticsearch": "^7.10.0",
44
- "@ocap/indexdb": "1.13.19",
45
- "@ocap/util": "1.13.19",
44
+ "@ocap/indexdb": "1.13.20",
45
+ "@ocap/util": "1.13.20",
46
46
  "axios": "^0.21.4",
47
47
  "bn.js": "^5.2.0",
48
48
  "debug": "^4.3.2",