-
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
[Discuss] Enhancement/saved object search #15175
Closed
chrisronline
wants to merge
11
commits into
elastic:master
from
chrisronline:enhancement/saved_object_search
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6f786cb
Some initial thoughts around improving saved object searching
chrisronline a8ee594
Provide a way to dynamically update mappings and auto re-save saved o…
chrisronline 7496f6a
Remove console.log
chrisronline bb3af0e
More specific code
chrisronline 577a67b
Try a more customizable approach
chrisronline 583d4d5
Support changes that require reindex too
chrisronline ee789eb
Remove change logic
chrisronline 7356cba
Go back to simple_query_string
chrisronline 0ae7183
Revert "Go back to simple_query_string"
chrisronline 9ab7c4b
PR feedback
chrisronline 129743d
Use getProperty
chrisronline 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
25 changes: 25 additions & 0 deletions
25
src/core_plugins/elasticsearch/lib/kibana_index_patches/patch_missing_properties.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,25 @@ | ||
import { getRootProperties } from '../../../../server/mappings'; | ||
|
||
export const patchMissingProperties = { | ||
id: 'missing_properties', | ||
|
||
async getUpdatedPatchMappings(context) { | ||
const { | ||
kibanaIndexMappingsDsl, | ||
currentMappingsDsl | ||
} = context; | ||
|
||
const expectedProps = getRootProperties(kibanaIndexMappingsDsl); | ||
const existingProps = getRootProperties(currentMappingsDsl); | ||
|
||
return Object.keys(expectedProps) | ||
.reduce((acc, prop) => { | ||
if (existingProps[prop]) { | ||
return acc; | ||
} else { | ||
console.log('missing'); | ||
return { ...acc || {}, [prop]: expectedProps[prop] }; | ||
} | ||
}, null); | ||
} | ||
}; |
82 changes: 82 additions & 0 deletions
82
...core_plugins/elasticsearch/lib/kibana_index_patches/patch_missing_title_keyword_fields.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,82 @@ | ||
import { | ||
getRootProperties, | ||
getProperty | ||
} from '../../../../server/mappings'; | ||
|
||
import { get } from 'lodash'; | ||
|
||
|
||
export const patchMissingTitleKeywordFields = { | ||
id: 'missing_title_keyword_fields', | ||
|
||
async getUpdatedPatchMappings(context) { | ||
const { | ||
currentMappingsDsl, | ||
kibanaIndexMappingsDsl, | ||
} = context; | ||
|
||
const properties = getRootProperties(currentMappingsDsl); | ||
const propertiesWithTitleKeyword = Object.keys(getRootProperties(kibanaIndexMappingsDsl)) | ||
.filter(property => Boolean(getProperty(kibanaIndexMappingsDsl, [property, 'title', 'keyword']))); | ||
const mappings = {}; | ||
|
||
for (const property of propertiesWithTitleKeyword) { | ||
const hasKeyword = !!get(properties, `${property}.properties.title.fields.keyword`); | ||
if (hasKeyword) { | ||
continue; | ||
} | ||
|
||
const titleMapping = get(properties, `${property}.properties.title`); | ||
mappings[property] = { | ||
properties: { | ||
title: { | ||
...titleMapping, | ||
fields: { | ||
keyword: { | ||
type: 'keyword', | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
// Make sure we return a falsy value | ||
if (!Object.keys(mappings).length) { | ||
return; | ||
} | ||
|
||
return mappings; | ||
}, | ||
|
||
async applyChanges(context) { | ||
const { | ||
patchMappings, | ||
callCluster, | ||
indexName, | ||
rootEsType, | ||
log, | ||
} = context; | ||
|
||
const properties = Object.keys(patchMappings); | ||
const types = properties.map(type => ({ match: { type } })); | ||
|
||
log(['info', 'elasticsearch'], { | ||
tmpl: `Updating by query for Saved Object types "<%= names.join('", "') %>"`, | ||
names: properties, | ||
}); | ||
|
||
await callCluster('updateByQuery', { | ||
conflicts: 'proceed', | ||
index: indexName, | ||
type: rootEsType, | ||
body: { | ||
query: { | ||
bool: { | ||
should: types, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
}; |
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
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.
Maybe explain the reason for this a bit? @elastic/kibana-discovery any idea how we can prevent this from being necessary?
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.
Would need to know requirements
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 changed this so we can support letting the user prefix the query with a wildcard, (request).
So, if we had the following four visualizations stored:
My Vis
,My_Vis
,My-Vis
,MyVis
, the user could query against*Vis
and return all four results.If we use
simple_query_string
, it seems to filter out the wildcard and only returns two results (My Vis
andMy-Vis
).This mirrors the search behavior you'd see in a text editor which felt natural and right to me, but it's fair to suggest we do not want to support it.
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, leading wildcard is generally regarded as a problem and simple_query_string probably doesn't allow it. I think that for Kibana's use case it would make sense to use a tokenizer that converts
My Vis
,My_Vis
,My-Vis
, andMyVis
all intomy
andvis
... Is that an option given the fact that we're going to update_by_query anyway?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.
Ngrams could be helpful https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html
But I also wonder whether a leading wildcard will really be a problem over the set of vis documents. .kibana is generally going to be really small. We could add a config to turn wildcards off if we're really paranoid.
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'm not concerned about the performance of leading wildcards in saved objects, but I am concerned about switching away from simple_query_string, didn't know you could configure simple_query_string to allow leading wildcards
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 don't think we can support leading wildcards with just
simple_query_string
:"reason": "[simple_query_string] unsupported field [allow_leading_wildcard]"
@spalger Can you help me understand the dangers of switching from
simple_query_string
toquery_string
?The docs say:
But it feels we easily mitigate the exception by catching it within Kibana server and returning an empty result set?
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 don't fully understand the ramifications of moving from
simple_query_string
toquery_string
, but I'm almost certain it's more than just about ignoring errors... Maybe @dakrone could help us understand the impact switching might have on Kibana?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.
Coming into this with no history, so I'm not really sure exactly where this is going to be used but...
flags
(not sure if this is useful to you)(foo | bar) + baz
being different than(foo OR bar) AND baz
To weigh in my unsolicited opinion, If you are comfortable with ngrams as @Bargs recommended, that would be a much easier way to support sub-string search without resorting to fancy querying. You could even have multiple fields and search both, just boosting the non-ngram version.
Hopefully that helps, happy to clarify more if I can.
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.
Thanks for the information @dakrone!!
I'll continue to investigate ngrams, but it feels like, for this use case, switching from SQS to QS is a viable option still.