SOR.find: allow to specify per-type search fields #119618
Closed
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.
Summary
Fix #130616
When we added a
match_phrase_prefix
clauses in #82693 to improve the results when searching with a prefix search (search term ending with*
), we overlooked thatmatch_phrase_prefix
must be performed against atext
field. Generating such clause against akeyword
field returns an error looking like:The problem with that is the behavior when searching for multiple types at once, as the SOM backend it doing.
Let say, for instance, that we got two types:
and
When filtering to both those types and searching by query from the SOM UI, the request to
SOR.find
created here:src/plugins/saved_objects_management/server/routes/find.ts
looks like:Causing
match_phrase_prefix
clauses to be created for all tuples:a.title
a.name
b.title
b.name
But because
b.title
is indexed askeyword
, the whole search fail.This is problematic because that forces all type owners to specify fields that are registered as
defaultSearchField
by other types to be registered astext
and notkeyword
. Such side effect makes no sense and should be avoided.We already encountered at least 4 times in the past few months issues because teams added new SO types with fields indexed as
keyword
that were already defined by existing SO types as theirdefaultSearchField
.This PR fixes this by allowing to specify per-type
searchFields
when callingSOC.find
.The previous API call now looks like:
Causing match_phrase_prefix clauses to now only be created for:
a.title
b.name
Note: Because this PR intent is to fix the bug causing the SOM requests to fail because of the described issue, the PR only uses these per-type fields for the
match_phrase_prefix
clauses of the ES request. Thesimple_query_string
part is still using all fields. The reason is simply that doing so would have caused way more changes in thesearch_dsl
logic, without much upsides.Checklist