es-alchemy
Advanced tools
Comparing version 8.4.2 to 8.5.0
@@ -16,7 +16,8 @@ "use strict"; | ||
module.exports = (call, idx, allowedFields, field, opts) => { | ||
module.exports = (call, idx, allowedFields, fields, opts) => { | ||
Joi.assert(opts, Joi.object().keys({ | ||
filterBy: Joi.object().optional(), | ||
limit: Joi.number().integer().min(1).optional(), | ||
cursor: Joi.string().optional() | ||
cursor: Joi.string().optional(), | ||
count: Joi.boolean().optional() | ||
}).nand('limit', 'cursor')); | ||
@@ -26,2 +27,3 @@ const cursorPayload = opts.cursor === undefined ? null : fromCursor(opts.cursor); | ||
const limit = get(cursorPayload, 'limit', get(opts, 'limit', 20)); | ||
const count = opts.count === undefined ? false : opts.count; | ||
const body = { | ||
@@ -35,3 +37,3 @@ size: 0, | ||
size: limit, | ||
sources: [{ | ||
sources: (Array.isArray(fields) ? fields : [fields]).map(field => ({ | ||
[field]: { | ||
@@ -42,3 +44,3 @@ terms: { | ||
} | ||
}] | ||
})) | ||
} | ||
@@ -65,3 +67,6 @@ } | ||
const result = { | ||
uniques: uniques.buckets.map(e => e.key[field]) | ||
uniques: uniques.buckets.map(e => { | ||
const value = Array.isArray(fields) ? fields.map(field => e.key[field]) : e.key[fields]; | ||
return count ? [value, e.doc_count] : value; | ||
}) | ||
}; | ||
@@ -68,0 +73,0 @@ |
{ | ||
"name": "es-alchemy", | ||
"version": "8.4.2", | ||
"version": "8.5.0", | ||
"description": "Simplification of Elasticsearch interactions", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -412,3 +412,3 @@ # ESAlchemy | ||
- `data.synced(index: String)` - returns true if all local index version exists on remote and have the same document count | ||
- `data.uniques(index: String, field: String, opts = { filterBy = {}, limit = 20, cursor = null })` - get unique values from index for field, using filter | ||
- `data.uniques(index: String, fields: String[] || String, opts = { filterBy = {}, limit = 20, cursor = null, count = boolean })` - get unique values from index for field, using filter. When count true, the counts per unique are returned | ||
- `data.update(options: Object)` - update or delete documents in Elasticsearch (all index versions) | ||
@@ -415,0 +415,0 @@ - `data.version(index: String, id: String)` - get version number in alias for document or null if document does not exist |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72447
1640