Skip to content

Commit

Permalink
[Advanced Settings] Fix search does not work for terms with ":" (#193506
Browse files Browse the repository at this point in the history
)

## Summary

Fixes #192694

When terms with `:`, it will be transformed to a `FieldClause`.

So, I'm try to set it back to a `TermClause` if the field is not in
`FieldDefinition`.

Example: `-defaultValue:false doc_table:high Dashboard`


![image](https://github.com/user-attachments/assets/e9519cfe-c64d-4bd4-b928-d6ffd9bfaa8b)

---------

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Elena Stoeva <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 2492981 commit b8398c7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/kbn-management/settings/application/hooks/use_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { Query } from '@elastic/eui';
import { Ast, Query } from '@elastic/eui';
import { getFieldDefinitions } from '@kbn/management-settings-field-definition';
import { FieldDefinition } from '@kbn/management-settings-types';
import { UiSettingsScope } from '@kbn/core-ui-settings-common';
import { Clause } from '@elastic/eui/src/components/search_bar/query/ast';
import { useServices } from '../services';
import { CATEGORY_FIELD } from '../query_input';
import { useSettings } from './use_settings';

/**
Expand All @@ -29,7 +31,19 @@ export const useFields = (scope: UiSettingsScope, query?: Query): FieldDefinitio
isOverridden: (key) => isOverriddenSetting(key, scope),
});
if (query) {
return Query.execute(query, fields);
const clauses: Clause[] = query.ast.clauses.map((clause) =>
// If the clause value contains `:` and is not a category filter, add it as a term clause
// This allows searching for settings that include `:` in their names
clause.type === 'field' && clause.field !== CATEGORY_FIELD
? {
type: 'term',
match: 'must',
value: `${clause.field}:${clause.value}`,
}
: clause
);

return Query.execute(new Query(Ast.create(clauses), undefined, query.text), fields);
}
return fields;
};

0 comments on commit b8398c7

Please sign in to comment.