[ES body removal] @elastic/observability-ui (#204873)

This commit is contained in:
Alejandro Fernández Haro 2025-02-02 18:10:02 +01:00 committed by GitHub
parent 777897cfa7
commit e01208030b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 40 deletions

View file

@ -66,7 +66,7 @@ export async function analyzeDocuments({
})
.then((response) => ({
hits: response.hits.hits.map((hit) =>
mapValues(hit.fields!, (value) => (value.length === 1 ? value[0] : value))
mapValues(hit.fields!, (value) => (value?.length === 1 ? value[0] : value))
),
total: response.hits.total,
})),

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { ESSearchResponse } from '@kbn/es-types';
import { useKibana } from '@kbn/kibana-react-plugin/public';

View file

@ -92,46 +92,44 @@ export const useValuesList = ({
const { data, loading } = useEsSearch(
createEsParams({
index: dataViewTitle!,
body: {
query: {
bool: {
filter: [
...(filters ?? []),
...(from && to
? [
{
range: {
'@timestamp': {
gte: from,
lte: to,
},
},
},
]
: []),
],
},
},
size: 0,
aggs: {
values: {
terms: {
field: sourceField,
size: 50,
...(query ? { include: includeClause } : {}),
},
...(cardinalityField
? {
aggs: {
count: {
cardinality: {
field: cardinalityField,
query: {
bool: {
filter: [
...(filters ?? []),
...(from && to
? [
{
range: {
'@timestamp': {
gte: from,
lte: to,
},
},
},
}
: {}),
]
: []),
],
},
},
size: 0,
aggs: {
values: {
terms: {
field: sourceField,
size: 50,
...(query ? { include: includeClause } : {}),
},
...(cardinalityField
? {
aggs: {
count: {
cardinality: {
field: cardinalityField,
},
},
},
}
: {}),
},
},
}),

View file

@ -5,10 +5,11 @@
* 2.0.
*/
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { kqlQuerySchema, QuerySchema } from '@kbn/slo-schema';
import { buildEsQuery, fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
export function getElasticsearchQueryOrThrow(kuery: QuerySchema = '') {
export function getElasticsearchQueryOrThrow(kuery: QuerySchema = ''): QueryDslQueryContainer {
try {
if (kqlQuerySchema.is(kuery)) {
return toElasticsearchQuery(fromKueryExpression(kuery));
@ -23,6 +24,6 @@ export function getElasticsearchQueryOrThrow(kuery: QuerySchema = '') {
);
}
} catch (err) {
return [];
return [] as QueryDslQueryContainer;
}
}