-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SavedObjectClient.find multiple types #19231
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e259046
Making the SavedObjectsClient.find accept a string or string[] for type
kobelb ac21609
Searching is now filtered to actual types
kobelb ec799fc
Adding multi-type sort
kobelb 7ac9f12
Merge remote-tracking branch 'upstream/master' into saved-object-types
kobelb 8572a90
Changing another use of includeTypes
kobelb a44879e
Fixing test's reliance on type
kobelb 3f1893e
Changing the find route to take type as an array
kobelb 27423c2
Can't sort on type... it's not a property on the object
kobelb d888756
Only allowing sorting on multiple types if it's a root property
kobelb 447783a
Expanding indicator of root property object
kobelb 60867c1
Sorting by type, now that it's allowed and one of the few sort columns
kobelb 2d7bfdb
Adjusting comment
kobelb babe758
Merge remote-tracking branch 'upstream/master' into saved-object-types
kobelb 8fafe43
Throwing better error message
kobelb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
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
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 field"`; | ||
|
||
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 field"`; | ||
|
||
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 field"`; | ||
|
||
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 field"`; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should say "... to designate that this is a type"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm. I guess we are calling these "root properties objects", so maybe type makes sense? But to me personally, the root properties object is the same thing as a top level type. Maybe saying "... to designate that this is a top level mapping type"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the naming is quite weird. I was trying to keep the way we were parsing the mappings separate from their usage within Kibana's saved objects, which prevented me from naming it
getSavedObjectTypes
. Perhaps going with a long and somewhat clumsy name ofgetRootPropertiesThatAreObjectDatatypes
is better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment wasn't talking about saved objects in particular. I was thinking of the elasticsearch naming, of "top level mapping type" which seems like a common way to describe that thing.
But ah, there's always the top level
_doc
type, so everything below it is just some thing, which we call types in Kibana, but which are genericallyObject Datatype
s.Does that above diagram describe it?
I now think the comment should say ".. that this is an object datatype"