-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* SavedObjectClient.find multiple types (#19231) * Making the SavedObjectsClient.find accept a string or string[] for type * Searching is now filtered to actual types * Adding multi-type sort * Changing another use of includeTypes * Fixing test's reliance on type * Changing the find route to take type as an array * Can't sort on type... it's not a property on the object * Only allowing sorting on multiple types if it's a root property * Expanding indicator of root property object * Sorting by type, now that it's allowed and one of the few sort columns * Adjusting comment * Throwing better error message * Updating search_dsl error snapshots after changing error message (#19394)
- Loading branch information
Showing
19 changed files
with
439 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ export { | |
getRootType, | ||
getProperty, | ||
getRootProperties, | ||
getRootPropertiesObjects, | ||
} from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getRootProperties } from './get_root_properties'; | ||
|
||
/** | ||
* Get the property mappings for the root type in the EsMappingsDsl | ||
* where the properties are objects | ||
* | ||
* If the mappings don't have a root type, or the root type is not | ||
* an object type (it's a keyword or something) this function will | ||
* throw an error. | ||
* | ||
* This data can be found at `{indexName}.mappings.{typeName}.properties` | ||
* in the es indices.get() response where the properties are objects. | ||
* | ||
* @param {EsMappingsDsl} mappings | ||
* @return {EsPropertyMappings} | ||
*/ | ||
export function getRootPropertiesObjects(mappings) { | ||
const rootProperties = getRootProperties(mappings); | ||
return Object.entries(rootProperties).reduce((acc, [key, value]) => { | ||
|
||
// we consider the existence of the properties or type of object to designate that this is an object datatype | ||
if (value.properties || value.type === 'object') { | ||
acc[key] = value; | ||
} | ||
|
||
return acc; | ||
}, {}); | ||
} |
166 changes: 166 additions & 0 deletions
166
src/server/mappings/lib/get_root_properties_objects.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { getRootPropertiesObjects } from './get_root_properties_objects'; | ||
|
||
test(`returns single object with properties`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
properties: {} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
properties: {} | ||
} | ||
}); | ||
}); | ||
|
||
test(`returns single object with type === 'object'`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
type: 'object' | ||
} | ||
}); | ||
}); | ||
|
||
test(`returns two objects with properties`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
properties: {} | ||
}, | ||
bar: { | ||
properties: {} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
properties: {} | ||
}, | ||
bar: { | ||
properties: {} | ||
} | ||
}); | ||
}); | ||
|
||
test(`returns two objects with type === 'object'`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
type: 'object' | ||
}, | ||
bar: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
type: 'object' | ||
}, | ||
bar: { | ||
type: 'object' | ||
} | ||
}); | ||
}); | ||
|
||
test(`excludes objects without properties and type of keyword`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
type: 'keyword' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
test(`excludes two objects without properties and type of keyword`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
type: 'keyword' | ||
}, | ||
bar: { | ||
type: 'keyword' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
test(`includes one object with properties and excludes one object without properties`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
properties: {} | ||
}, | ||
bar: { | ||
type: 'keyword' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
properties: {} | ||
} | ||
}); | ||
}); | ||
|
||
test(`includes one object with type === 'object' and excludes one object without properties`, () => { | ||
const mappings = { | ||
rootType: { | ||
properties: { | ||
foo: { | ||
type: 'object' | ||
}, | ||
bar: { | ||
type: 'keyword' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const result = getRootPropertiesObjects(mappings); | ||
expect(result).toEqual({ | ||
foo: { | ||
type: 'object' | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/server/saved_objects/client/lib/search_dsl/__snapshots__/sorting_params.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`searchDsl/getSortParams sort with direction sortField is non-root multi-field with multiple types returns correct params 1`] = `"Unable to sort multiple types by field title.raw, not a root property"`; | ||
|
||
exports[`searchDsl/getSortParams sort with direction sortFields is non-root simple property with multiple types returns correct params 1`] = `"Unable to sort multiple types by field title, not a root property"`; | ||
|
||
exports[`searchDsl/getSortParams sortField no direction sortField is not-root multi-field with multiple types returns correct params 1`] = `"Unable to sort multiple types by field title.raw, not a root property"`; | ||
|
||
exports[`searchDsl/getSortParams sortField no direction sortField is simple non-root property with multiple types returns correct params 1`] = `"Unable to sort multiple types by field title, not a root property"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.