mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Use arrow syntax instead of bind, infinity instead of number infinity
This commit is contained in:
parent
7acd69563c
commit
43f883979b
4 changed files with 30 additions and 31 deletions
|
@ -52,8 +52,8 @@ define(function (require) {
|
|||
this.scanAll = function (queryString, pageSize = 1000) {
|
||||
return scanner.scanAndMap(queryString, {
|
||||
pageSize,
|
||||
docCount: Number.POSITIVE_INFINITY
|
||||
}, this.mapHits.bind(this));
|
||||
docCount: Infinity
|
||||
}, (hit) => this.mapHits(hit));
|
||||
};
|
||||
|
||||
this.mapHits = function (hit) {
|
||||
|
@ -64,7 +64,6 @@ define(function (require) {
|
|||
};
|
||||
|
||||
this.find = function (searchString, size = 100) {
|
||||
var self = this;
|
||||
var body;
|
||||
if (searchString) {
|
||||
body = {
|
||||
|
@ -86,10 +85,10 @@ define(function (require) {
|
|||
body: body,
|
||||
size: size
|
||||
})
|
||||
.then(function (resp) {
|
||||
.then((resp) => {
|
||||
return {
|
||||
total: resp.hits.total,
|
||||
hits: resp.hits.hits.map(self.mapHits.bind(self))
|
||||
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -39,8 +39,8 @@ define(function (require) {
|
|||
this.scanAll = function (queryString, pageSize = 1000) {
|
||||
return scanner.scanAndMap(queryString, {
|
||||
pageSize,
|
||||
docCount: Number.POSITIVE_INFINITY
|
||||
}, this.mapHits.bind(this));
|
||||
docCount: Infinity
|
||||
}, (hit) => this.mapHits(hit));
|
||||
};
|
||||
|
||||
|
||||
|
@ -67,7 +67,6 @@ define(function (require) {
|
|||
};
|
||||
|
||||
this.find = function (searchString, size = 100) {
|
||||
var self = this;
|
||||
var body;
|
||||
if (searchString) {
|
||||
body = {
|
||||
|
@ -89,10 +88,10 @@ define(function (require) {
|
|||
body: body,
|
||||
size: size
|
||||
})
|
||||
.then(function (resp) {
|
||||
.then((resp) => {
|
||||
return {
|
||||
total: resp.hits.total,
|
||||
hits: resp.hits.hits.map(self.mapHits.bind(self))
|
||||
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -51,8 +51,8 @@ define(function (require) {
|
|||
this.scanAll = function (queryString, pageSize = 1000) {
|
||||
return scanner.scanAndMap(queryString, {
|
||||
pageSize,
|
||||
docCount: Number.POSITIVE_INFINITY
|
||||
}, this.mapHits.bind(this));
|
||||
docCount: Infinity
|
||||
}, (hit) => this.mapHits(hit));
|
||||
};
|
||||
|
||||
this.mapHits = function (hit) {
|
||||
|
@ -78,7 +78,6 @@ define(function (require) {
|
|||
};
|
||||
|
||||
this.find = function (searchString, size = 100) {
|
||||
var self = this;
|
||||
var body;
|
||||
if (searchString) {
|
||||
body = {
|
||||
|
@ -100,10 +99,10 @@ define(function (require) {
|
|||
body: body,
|
||||
size: size
|
||||
})
|
||||
.then(function (resp) {
|
||||
.then((resp) => {
|
||||
return {
|
||||
total: resp.hits.total,
|
||||
hits: resp.hits.hits.map(self.mapHits.bind(self))
|
||||
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
var Scanner = function (client, {index, type}) {
|
||||
let Scanner = function (client, {index, type}) {
|
||||
if (!index) throw new Error('Expected index');
|
||||
if (!type) throw new Error('Expected type');
|
||||
if (!client) throw new Error('Expected client');
|
||||
|
@ -16,12 +16,12 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {
|
|||
docCount: 1000
|
||||
}, options);
|
||||
|
||||
var allResults = {
|
||||
let allResults = {
|
||||
hits: [],
|
||||
total: 0
|
||||
};
|
||||
|
||||
var body;
|
||||
let body;
|
||||
if (searchString) {
|
||||
body = {
|
||||
query: {
|
||||
|
@ -37,24 +37,17 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {
|
|||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.search({
|
||||
index: this.index,
|
||||
type: this.type,
|
||||
size: opts.pageSize,
|
||||
body,
|
||||
searchType: 'scan',
|
||||
scroll: '1m'
|
||||
}, function getMoreUntilDone(error, response) {
|
||||
var scanAllResults = opts.docCount === Number.POSITIVE_INFINITY;
|
||||
const getMoreUntilDone = (error, response) => {
|
||||
const scanAllResults = opts.docCount === Infinity;
|
||||
allResults.total = scanAllResults ? response.hits.total : Math.min(response.hits.total, opts.docCount);
|
||||
|
||||
var hits = response.hits.hits
|
||||
let hits = response.hits.hits
|
||||
.slice(0, allResults.total - allResults.hits.length);
|
||||
if (mapFn) hits = hits.map(mapFn);
|
||||
|
||||
allResults.hits = allResults.hits.concat(hits);
|
||||
|
||||
var collectedAllResults = allResults.total === allResults.hits.length;
|
||||
const collectedAllResults = allResults.total === allResults.hits.length;
|
||||
if (collectedAllResults) {
|
||||
resolve(allResults);
|
||||
} else {
|
||||
|
@ -62,7 +55,16 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {
|
|||
scrollId: response._scroll_id,
|
||||
}, getMoreUntilDone);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.client.search({
|
||||
index: this.index,
|
||||
type: this.type,
|
||||
size: opts.pageSize,
|
||||
body,
|
||||
searchType: 'scan',
|
||||
scroll: '1m'
|
||||
}, getMoreUntilDone);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue