Skip to content
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

[App Search] Fixed 2 relevance tuning bugs #94312

Merged
merged 2 commits into from
Mar 10, 2021

Conversation

JasonStoltz
Copy link
Member

@JasonStoltz JasonStoltz commented Mar 10, 2021

Summary

Bug 1: Selecting a "Functional" boost for a "Date" field will result in a "Functional boosts are not supported for Date fields..." error message.

The fix for that is here: ea0a3af

To Test:

  • Create an engine that has a "Date" field in its schema
  • Navigate to Your engine > Relevance Tuning > your date field > "Add Boost" > you should not see "Functional" listed as an option, only "Value" and "Proximity"

Bug 2: Selecting a "Functional" or "Proximity" boost and pressing save, without selecting an option, was causing an error.

The root cause was that when creating new Functional and Proximity boosts in state, we were not initializing all required fields of the boost. So when we attempt to post it to the server, the server was rejecting it as invalid

As it turns out, the reason we missed this on the initial implementation, is because that initialization was actually happening in the view, rather than Kea in the old repository. I.e., when the view was initialized, it was actually mutating the newly created boosts in state directly, rather than using a kea action. This is a pretty clear anti-pattern. My fix for this is to initialize the missing values as part of the "addBoost" action in Kea: 05ccd18. https://github.com/elastic/kibana/pull/94312/files#diff-8f932314a95e85fb9e58bdfb28af437b2d3be46a00caa15052d09619f96bf26eR373

Note that as part of this, I refactored the Boost types a bit to make the schema more clear. There is now a parent Boost type as well as child FunctionalBoost, ValueBoost, and ProximityBoost types, to make it clear which Boost fields are used for which boost types.

To test:

  • Create an engine that has a "Number" field in its schema
  • Navigate to Your engine > Relevance Tuning > your number field > "Add Boost" > "Functional"
  • Observe that the Functional boost is created in the UI with the dropdowns pre-populated.
  • Use the "Save" button to save the new boost.
  • You should not see an error.
  • You should see that the Functional boost is still on the page and was persisted.
  • Repeat the previous steps for a Proximity boost (note that you will need to enter a "center" value in order to save this one properly). The center value is not pre-populated.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@JasonStoltz JasonStoltz requested a review from a team March 10, 2021 15:35
@JasonStoltz JasonStoltz changed the title [App Search] Fix 2 relevance tuning bugs [App Search] Fixed 2 relevance tuning bugs Mar 10, 2021
@JasonStoltz JasonStoltz added v7.13.0 release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed labels Mar 10, 2021
@JasonStoltz JasonStoltz enabled auto-merge (squash) March 10, 2021 15:37
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 2.1MB 2.1MB +739.0B

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for catching these bugs Jason, and partial apologies on my end for not QAing more thoroughly! I can confirm the date select option & the Functional boost bugs being fixed.

As a heads up I can't quite confirm the Proximity bug though - it appears to be working for me as expected on master. If I create a Proximity boost and don't enter or change anything and just hit saves, it errors that it's missing a center (which I would expect). If I create a new Proximity boost & enter a center but don't click anything else, it saves without errors.

That behavior is the same before/after this branch and seems correct to me so I'm not concerned / approving in any case, but just wanted to confirm my understanding of that behavior with you.

type: BoostType;
newBoost?: boolean;
center?: string | number;
export interface RawBoost extends Omit<Boost, 'value'> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Awesome use of omit!

Comment on lines 34 to +39
operation?: BoostOperation;
function?: BoostFunction;
newBoost?: boolean;
center?: string | number;
factor: number;
value?: string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just curious, feel free to stop me if I'm missing something)

Do we really need this base Boost type any longer if the more specific Boost types below are overriding value, function, and operation in any case? 🤷

Copy link
Member Author

@JasonStoltz JasonStoltz Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason it's nice to have that is for when we're passing a boost around in the general sense, and don't really care what type of boost it is.

Like in a reducer I can accept any Boost as a prop and check its newBoost prop. I don't really care what type of Boost it is, I just care that it's a Boost, and all Boosts have a newBoost prop. If I need to do something FunctionalBoost specific, I can cast it to FunctionalBoost.

It's kind of like a classic inheritance thing, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, totally makes sense! Thanks for taking the time to explain!

value: BoostOperation | BoostFunction
): {
name: string;
boostIndex: number;
optionType: keyof BaseBoost;
optionType: keyof Pick<Boost, 'operation' | 'function'>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind walking me through what the output of this actually looks like? I think I'd get both keyof and Pick separately, but that + | is tripping me up. Just want to make sure I understand what this compiles to!

Copy link
Member Author

@JasonStoltz JasonStoltz Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boost:

{
  operation?: BoostOperation;
  function?: BoostFunction;
  type: BoostType;
  newBoost?: boolean;
  center?: string | number;
  factor: number;
 ...
}

Pick<Boost, 'operation' | 'function'>:

{
  operation?: BoostOperation;
  function?: BoostFunction;
}

keyof Pick<Boost, 'operation' | 'function'>

'operation' | 'function'

So it's a stupid long way of writing 'operation' | 'function'

Whatever is passed in optionType is ultimately used to update the boost by that key...

optionsType = 'operation'
boost[optionType] = whatever

So I wanted to make it clear that there is an association between optionType and keys within a boost.

Writing them as follows just makes them feel a bit like magic strings...

optionType: 'operation' | 'function'

But for simplicity maybe that would be preferable.

Sorry, I realize this is confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think, should I simplify this in my next PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh whoa I was way off in my guess on what that compiled to lol. I think I'd opt for simplicity if that's OK with you - it doesn't feel too magical to me / feels like a more straightforward string enum, but maybe I'm missing something 🤔

@@ -376,7 +370,7 @@ export const RelevanceTuningLogic = kea<
addBoost: ({ name, type }) => {
const { searchSettings } = values;
const { boosts } = searchSettings;
const emptyBoost = { type, factor: 1, newBoost: true };
const emptyBoost = BOOST_TYPE_TO_EMPTY_BOOST[type];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm my understanding: this is essentially the fix, correct? (well, + the correct empty const definitions above)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry, there is a busy PR.

@JasonStoltz JasonStoltz merged commit a198744 into elastic:master Mar 10, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 10, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

7.x / #94357

Successful backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Mar 10, 2021
jloleysens added a commit that referenced this pull request Mar 11, 2021
…-action

* 'master' of github.com:elastic/kibana: (43 commits)
  [Console] Update copy when showing warnings in response headers (#94270)
  [TSVB] Type public code. Step 1 (#93231)
  [ML] Functional tests - stabilize slider value selection (#94313)
  skip another suite blocking es promotion (#94367)
  [Security Solution] Eliminates a redundant external link icon (#94194)
  skip another suite blocking es promotion (#94367)
  [App Search] Role mappings migration part 1 (#94346)
  [Security Solution][Detections] Fix flaky indicator enrichment tests (#94241)
  [Workplace Search] Deduplicate icons (#94359)
  [ML] Add latest transform to intro text (#94039)
  skip test failing es promotion (#94367)
  [Maps] convert elasticsearch_utils to TS (#93984)
  [Security_Solution][Telemetry] - Update endpoint usage to use agentService (#93829)
  [Security Solution][Exceptions] Fixes OS adding method for exception enrichment (#94343)
  [ILM] Add support for frozen phase (#93068)
  [App Search] Fixed 2 relevance tuning bugs (#94312)
  remove `try` auth mode (#94287)
  Removing resolver functional tests (#94331)
  migrate warning mixin to core (#94273)
  [App Search] Add routes for Role Mappings (#94221)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/cold_phase/cold_phase.tsx
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/phase/phase.tsx
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.tsx
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/configuration_issues_context.tsx
@JasonStoltz JasonStoltz deleted the filter-invalid-boost branch March 11, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants