pelias-schema 10.1.0 → 10.1.1
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.
package/configValidation.js
CHANGED
|
@@ -3,15 +3,15 @@ const Joi = require('@hapi/joi');
|
|
|
3
3
|
// Schema Configuration
|
|
4
4
|
// schema.indexName: populated by defaults if not overridden
|
|
5
5
|
// schema.icuTokenizer: boolean, optional, defaults to false
|
|
6
|
-
// schema.
|
|
7
|
-
// schema.
|
|
6
|
+
// schema.sourceExcludedFields: array of field paths to index but omit from _source, optional
|
|
7
|
+
// schema.unmappedFields: array of field paths to remove from the mapping, optional
|
|
8
8
|
// esclient: object, validation performed by elasticsearch module
|
|
9
9
|
const schema = Joi.object().required().keys({
|
|
10
10
|
schema: Joi.object().required().keys({
|
|
11
11
|
indexName: Joi.string().required(),
|
|
12
12
|
icuTokenizer: Joi.boolean().optional(),
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
sourceExcludedFields: Joi.array().items(Joi.string()).optional(),
|
|
14
|
+
unmappedFields: Joi.array().items(Joi.string()).optional()
|
|
15
15
|
}),
|
|
16
16
|
esclient: Joi.object().required()
|
|
17
17
|
}).unknown(true);
|
|
@@ -6,21 +6,21 @@ const mappingPath = (field) => _.flatMap(field.split('.'), (part) => ['propertie
|
|
|
6
6
|
/**
|
|
7
7
|
* apply field configuration from `schema` section of pelias config to a mapping
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* sourceExcludedFields: fields that are indexed but omitted from _source
|
|
10
|
+
* unmappedFields: fields removed from the mapping entirely
|
|
11
11
|
*/
|
|
12
12
|
function configureFields(mapping, schemaConfig) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const sourceExcluded = _.get(schemaConfig, 'sourceExcludedFields', []);
|
|
14
|
+
const unmapped = _.get(schemaConfig, 'unmappedFields', []);
|
|
15
15
|
|
|
16
16
|
const configured = _.cloneDeep(mapping);
|
|
17
17
|
|
|
18
|
-
if (!_.isEmpty(
|
|
18
|
+
if (!_.isEmpty(sourceExcluded)) {
|
|
19
19
|
const excludes = _.get(configured, '_source.excludes', []);
|
|
20
|
-
_.set(configured, '_source.excludes', _.union(excludes,
|
|
20
|
+
_.set(configured, '_source.excludes', _.union(excludes, sourceExcluded));
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
unmapped.forEach((field) => _.unset(configured, mappingPath(field)));
|
|
24
24
|
|
|
25
25
|
return configured;
|
|
26
26
|
}
|
package/package.json
CHANGED
package/test/configValidation.js
CHANGED
|
@@ -84,12 +84,12 @@ module.exports.tests.interface = function(test, common) {
|
|
|
84
84
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
test('config with array of strings for
|
|
87
|
+
test('config with array of strings for sourceExcludedFields and unmappedFields should not throw error', function(t) {
|
|
88
88
|
var config = {
|
|
89
89
|
schema: {
|
|
90
90
|
indexName: 'example_index',
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
sourceExcludedFields: ['addendum', 'parent.county_a'],
|
|
92
|
+
unmappedFields: ['popularity']
|
|
93
93
|
},
|
|
94
94
|
esclient: {}
|
|
95
95
|
};
|
|
@@ -101,8 +101,8 @@ module.exports.tests.interface = function(test, common) {
|
|
|
101
101
|
t.end();
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
test('config with non-array
|
|
105
|
-
['
|
|
104
|
+
test('config with non-array sourceExcludedFields or unmappedFields should throw error', function(t) {
|
|
105
|
+
['sourceExcludedFields', 'unmappedFields'].forEach((key) => {
|
|
106
106
|
[null, 17, 'addendum', {}, true, [17]].forEach((value) => {
|
|
107
107
|
var config = {
|
|
108
108
|
schema: {
|
package/test/configureFields.js
CHANGED
|
@@ -3,24 +3,24 @@ const document = require('../mappings/document');
|
|
|
3
3
|
|
|
4
4
|
module.exports.tests = {};
|
|
5
5
|
|
|
6
|
-
module.exports.tests.
|
|
6
|
+
module.exports.tests.sourceExcluded = function(test, common) {
|
|
7
7
|
test('no config leaves mapping unchanged', function(t) {
|
|
8
8
|
t.deepEqual(configureFields(document, undefined), document);
|
|
9
9
|
t.deepEqual(configureFields(document, {}), document);
|
|
10
10
|
t.end();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
test('
|
|
14
|
-
const mapping = configureFields(document, {
|
|
13
|
+
test('sourceExcluded fields are appended to _source excludes', function(t) {
|
|
14
|
+
const mapping = configureFields(document, { sourceExcludedFields: ['addendum', 'parent.*_a', 'shape'] });
|
|
15
15
|
t.deepEqual(mapping._source.excludes, ['shape', 'phrase', 'addendum', 'parent.*_a']);
|
|
16
16
|
t.deepEqual(mapping.properties, document.properties, 'properties unchanged');
|
|
17
17
|
t.end();
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
module.exports.tests.
|
|
22
|
-
test('
|
|
23
|
-
const mapping = configureFields(document, {
|
|
21
|
+
module.exports.tests.unmapped = function(test, common) {
|
|
22
|
+
test('unmapped fields are removed from mapping', function(t) {
|
|
23
|
+
const mapping = configureFields(document, { unmappedFields: ['popularity', 'parent.county_a', 'not_a_field'] });
|
|
24
24
|
t.false(mapping.properties.popularity, 'top level field removed');
|
|
25
25
|
t.false(mapping.properties.parent.properties.county_a, 'nested field removed');
|
|
26
26
|
t.true(mapping.properties.parent.properties.county, 'sibling field kept');
|
|
@@ -29,7 +29,7 @@ module.exports.tests.excluded = function(test, common) {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('original mapping is not modified', function(t) {
|
|
32
|
-
configureFields(document, {
|
|
32
|
+
configureFields(document, { sourceExcludedFields: ['addendum'], unmappedFields: ['popularity', 'parent.county_a'] });
|
|
33
33
|
t.deepEqual(document._source.excludes, ['shape', 'phrase']);
|
|
34
34
|
t.true(document.properties.popularity);
|
|
35
35
|
t.true(document.properties.parent.properties.county_a);
|