-
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
Support v6 mappings for saved objects import/export #12792
Merged
tylersmalley
merged 3 commits into
elastic:master
from
tylersmalley:saved-objects-export
Jul 13, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -11,8 +11,9 @@ export const Scanner = function (client, { index, type } = {}) { | |
}; | ||
|
||
Scanner.prototype.scanAndMap = function (searchString, options, mapFn) { | ||
const bool = { must: [], filter: [] }; | ||
|
||
let scrollId; | ||
let body; | ||
const allResults = { | ||
hits: [], | ||
total: 0 | ||
|
@@ -22,18 +23,37 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) { | |
docCount: 1000 | ||
}); | ||
|
||
if (this.type) { | ||
bool.filter.push({ | ||
bool: { | ||
should: [ | ||
{ | ||
term: { | ||
_type: this.type | ||
} | ||
}, | ||
{ | ||
term: { | ||
type: this.type | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
} | ||
|
||
if (searchString) { | ||
body = { | ||
query: { | ||
simple_query_string: { | ||
query: searchString + '*', | ||
fields: ['title^3', 'description'], | ||
default_operator: 'AND' | ||
} | ||
bool.must.push({ | ||
simple_query_string: { | ||
query: searchString + '*', | ||
fields: ['title^3', 'description'], | ||
default_operator: 'AND' | ||
} | ||
}; | ||
}); | ||
} else { | ||
body = { query: { match_all: {} } }; | ||
bool.must.push({ | ||
match_all: {} | ||
}); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
|
@@ -48,6 +68,22 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) { | |
|
||
let hits = response.hits.hits | ||
.slice(0, allResults.total - allResults.hits.length); | ||
|
||
hits = hits.map(hit => { | ||
if (hit._type === 'doc') { | ||
return { | ||
_id: hit._id.replace(`${this.type}:`, ''), | ||
_type: this.type, | ||
_source: hit._source[this.type], | ||
_meta: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😻 |
||
savedObjectVersion: 2 | ||
} | ||
}; | ||
} | ||
|
||
return _.pick(hit, ['_id', '_type', '_source']); | ||
}); | ||
|
||
if (mapFn) hits = hits.map(mapFn); | ||
|
||
allResults.hits = allResults.hits.concat(hits); | ||
|
@@ -64,12 +100,10 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) { | |
|
||
this.client.search({ | ||
index: this.index, | ||
type: this.type, | ||
size: opts.pageSize, | ||
body, | ||
body: { query: { bool } }, | ||
scroll: '1m', | ||
sort: '_doc', | ||
}, getMoreUntilDone); | ||
}); | ||
}; | ||
|
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.
Why did you remove this? Are you sure this doesn't have trickle down effects elsewhere, on xpack or something?
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 couldn't find any instance of it being used and never ran into an error when testing.
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.
This is why I love getters so much, easier to find uses but mostly that unexpected accesses that are broken by changes/removal are much louder