Fix autocomplete value suggestions to exclude tiers (#176355)

## Summary

Resolves https://github.com/elastic/kibana/issues/165264.

When querying ES for value suggestions (KQL & filter editor), this PR
updates the behavior to filter *out* (instead of filter *for*) tiers.
This ensures that for those indices without a tier preference set, the
values will still show up.

The tiers are controlled by a config setting,
`data.autocomplete.valueSuggestions.tiers`. This may have already been
set, so we preserve the existing settings when querying.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### Release notes

Autocomplete value suggestions for KQL and filters will now return
suggestions even when the corresponding index has no tier preference
set.

---------

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
This commit is contained in:
Lukas Olson 2024-02-21 11:28:25 -07:00 committed by GitHub
parent 5244569476
commit 534c337831
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 41 deletions

View file

@ -57,17 +57,15 @@ describe('_terms_enum suggestions', () => {
"field": "field_name",
"index_filter": Object {
"bool": Object {
"must": Array [
Object {
"terms": Object {
"_tier": Array [
"data_hot",
"data_warm",
"data_content",
],
},
"must": Array [],
"must_not": Object {
"terms": Object {
"_tier": Array [
"data_cold",
"data_frozen",
],
},
],
},
},
},
"string": "query",
@ -97,17 +95,15 @@ describe('_terms_enum suggestions', () => {
"field": "fieldName",
"index_filter": Object {
"bool": Object {
"must": Array [
Object {
"terms": Object {
"_tier": Array [
"data_hot",
"data_warm",
"data_content",
],
},
"must": Array [],
"must_not": Object {
"terms": Object {
"_tier": Array [
"data_cold",
"data_frozen",
],
},
],
},
},
},
"string": "query",

View file

@ -23,36 +23,36 @@ export async function termsEnumSuggestions(
field?: FieldSpec,
abortSignal?: AbortSignal
) {
// See https://github.com/elastic/kibana/issues/165264
const { tiers } = config.autocomplete.valueSuggestions;
const excludedTiers = [
'data_content',
'data_hot',
'data_warm',
'data_cold',
'data_frozen',
].filter((tier) => !tiers.includes(tier));
if (!field?.name && !field?.type) {
const indexPattern = await findIndexPatternById(savedObjectsClient, index);
field = indexPattern && getFieldByName(fieldName, indexPattern);
}
const result = await esClient.termsEnum(
{
index,
body: {
field: field?.name ?? fieldName,
string: query,
index_filter: {
bool: {
must: [
...(filters ?? []),
{
terms: {
_tier: tiers,
},
},
],
const body = {
field: field?.name ?? fieldName,
string: query,
index_filter: {
bool: {
must: filters ?? [],
must_not: {
terms: {
_tier: excludedTiers,
},
},
},
},
{
signal: abortSignal,
}
);
};
return result.terms;
const { terms } = await esClient.termsEnum({ index, body }, { signal: abortSignal });
return terms;
}