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.
@@ -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.unstoredFields: array of field paths to index but omit from _source, optional
7
- // schema.excludedFields: array of field paths to remove from the mapping, optional
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
- unstoredFields: Joi.array().items(Joi.string()).optional(),
14
- excludedFields: Joi.array().items(Joi.string()).optional()
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
- * unstoredFields: fields that are indexed but omitted from _source
10
- * excludedFields: fields removed from the mapping entirely
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 unstored = _.get(schemaConfig, 'unstoredFields', []);
14
- const excluded = _.get(schemaConfig, 'excludedFields', []);
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(unstored)) {
18
+ if (!_.isEmpty(sourceExcluded)) {
19
19
  const excludes = _.get(configured, '_source.excludes', []);
20
- _.set(configured, '_source.excludes', _.union(excludes, unstored));
20
+ _.set(configured, '_source.excludes', _.union(excludes, sourceExcluded));
21
21
  }
22
22
 
23
- excluded.forEach((field) => _.unset(configured, mappingPath(field)));
23
+ unmapped.forEach((field) => _.unset(configured, mappingPath(field)));
24
24
 
25
25
  return configured;
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pelias-schema",
3
- "version": "10.1.0",
3
+ "version": "10.1.1",
4
4
  "author": "pelias",
5
5
  "description": "Elasticsearch schema files and tooling for Pelias",
6
6
  "homepage": "https://github.com/pelias/schema",
@@ -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 unstoredFields and excludedFields should not throw error', function(t) {
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
- unstoredFields: ['addendum', 'parent.county_a'],
92
- excludedFields: ['popularity']
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 unstoredFields or excludedFields should throw error', function(t) {
105
- ['unstoredFields', 'excludedFields'].forEach((key) => {
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: {
@@ -3,24 +3,24 @@ const document = require('../mappings/document');
3
3
 
4
4
  module.exports.tests = {};
5
5
 
6
- module.exports.tests.unstored = function(test, common) {
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('unstored fields are appended to _source excludes', function(t) {
14
- const mapping = configureFields(document, { unstoredFields: ['addendum', 'parent.*_a', 'shape'] });
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.excluded = function(test, common) {
22
- test('excluded fields are removed from mapping', function(t) {
23
- const mapping = configureFields(document, { excludedFields: ['popularity', 'parent.county_a', 'not_a_field'] });
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, { unstoredFields: ['addendum'], excludedFields: ['popularity', 'parent.county_a'] });
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);