From 94e379fa23779e78bfc4facc55ce258c28ed1489 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cau=C3=AA=20Marcondes?=
<55978943+cauemarcondes@users.noreply.github.com>
Date: Wed, 14 Jul 2021 14:55:07 -0400
Subject: [PATCH] [APM] Kuery bar gives invalid suggestions (#105132)
* adding method to support terms_agg
* adding more filters to kuery bar
* addressing PR comments
* fixing docs
* addressing PR comments
* moving file to common
* addressing PR comments
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
---
...ns-data-public.querysuggestiongetfnargs.md | 1 +
...-public.querysuggestiongetfnargs.method.md | 11 +++++++
src/plugins/data/common/constants.ts | 2 ++
.../providers/kql_query_suggestion/value.ts | 3 +-
.../providers/query_suggestion_provider.ts | 2 ++
.../providers/value_suggestion_provider.ts | 29 ++++++++++++++++---
src/plugins/data/public/public.api.md | 4 +++
.../autocomplete/value_suggestions_route.ts | 7 +++--
.../utils/environment_query.test.ts} | 6 ++--
.../utils/environment_query.ts} | 9 ++----
.../shared/kuery_bar/get_bool_filter.ts | 9 ++++++
.../components/shared/kuery_bar/index.tsx | 1 +
.../chart_preview/get_transaction_duration.ts | 3 +-
.../get_transaction_error_count.ts | 3 +-
.../get_transaction_error_rate.ts | 3 +-
.../alerts/register_error_count_alert_type.ts | 2 +-
...egister_transaction_duration_alert_type.ts | 2 +-
...ister_transaction_error_rate_alert_type.ts | 2 +-
.../create_anomaly_detection_jobs.ts | 2 +-
.../server/lib/correlations/get_filters.ts | 3 +-
.../lib/environments/get_environments.ts | 2 +-
.../lib/errors/distribution/get_buckets.ts | 7 ++---
.../lib/errors/get_error_group_sample.ts | 7 ++---
.../helpers/aggregated_transactions/index.ts | 2 +-
.../get_service_count.ts | 2 +-
.../get_transactions_per_minute.ts | 2 +-
.../apm/server/lib/rum_client/has_rum_data.ts | 2 +-
.../rum_client/ui_filters/get_es_filter.ts | 2 +-
.../correlations/get_query_with_params.ts | 11 +++----
.../fetch_service_paths_from_trace_ids.ts | 2 +-
.../lib/service_map/get_service_anomalies.ts | 2 +-
.../server/lib/service_map/get_service_map.ts | 2 +-
.../get_service_map_service_node_info.ts | 3 +-
.../lib/service_map/get_trace_sample_ids.ts | 3 +-
.../get_derived_service_annotations.ts | 3 +-
.../annotations/get_stored_annotations.ts | 3 +-
.../lib/services/get_service_agent_name.ts | 2 +-
.../server/lib/services/get_service_alerts.ts | 3 +-
.../get_destination_map.ts | 3 +-
.../get_service_dependencies/get_metrics.ts | 3 +-
...service_error_group_detailed_statistics.ts | 7 ++---
...get_service_error_group_main_statistics.ts | 7 ++---
.../get_service_error_groups/index.ts | 7 ++---
.../get_service_instance_metadata_details.ts | 3 +-
...vice_instances_system_metric_statistics.ts | 3 +-
...ervice_instances_transaction_statistics.ts | 3 +-
.../services/get_service_metadata_details.ts | 2 +-
.../services/get_service_metadata_icons.ts | 2 +-
...e_transaction_group_detailed_statistics.ts | 7 ++---
.../get_service_transaction_groups.ts | 7 ++---
.../services/get_service_transaction_types.ts | 2 +-
.../get_services/get_legacy_data_status.ts | 2 +-
.../get_service_transaction_stats.ts | 7 ++---
.../get_services_from_metric_documents.ts | 3 +-
.../apm/server/lib/services/get_throughput.ts | 7 ++---
.../get_service_profiling_statistics.ts | 7 ++---
.../get_service_profiling_timeline.ts | 4 +--
.../apm/server/lib/traces/get_trace_items.ts | 2 +-
.../lib/transaction_groups/get_error_rate.ts | 7 ++---
.../lib/transactions/breakdown/index.ts | 7 ++---
.../distribution/get_buckets/index.ts | 7 ++---
.../distribution/get_distribution_max.ts | 7 ++---
.../transactions/get_anomaly_data/fetcher.ts | 2 +-
.../transactions/get_latency_charts/index.ts | 7 ++---
.../get_throughput_charts/index.ts | 7 ++---
.../lib/transactions/get_transaction/index.ts | 2 +-
.../plugins/apm/server/projections/errors.ts | 7 ++---
.../plugins/apm/server/projections/metrics.ts | 7 ++---
.../projections/rum_page_load_transactions.ts | 2 +-
.../apm/server/projections/services.ts | 2 +-
.../apm/server/projections/transactions.ts | 7 ++---
71 files changed, 165 insertions(+), 158 deletions(-)
create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md
rename x-pack/plugins/apm/{server/utils/queries.test.ts => common/utils/environment_query.test.ts} (80%)
rename x-pack/plugins/apm/{server/utils/queries.ts => common/utils/environment_query.ts} (68%)
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md
index de6f4563b678..7c850a89dff1 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md
@@ -19,6 +19,7 @@ export interface QuerySuggestionGetFnArgs
| [boolFilter](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.boolfilter.md) | any
| |
| [indexPatterns](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.indexpatterns.md) | IIndexPattern[]
| |
| [language](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.language.md) | string
| |
+| [method](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md) | ValueSuggestionsMethod
| |
| [query](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.query.md) | string
| |
| [selectionEnd](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.selectionend.md) | number
| |
| [selectionStart](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.selectionstart.md) | number
| |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md
new file mode 100644
index 000000000000..2bc9a4fba61c
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [QuerySuggestionGetFnArgs](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md) > [method](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.method.md)
+
+## QuerySuggestionGetFnArgs.method property
+
+Signature:
+
+```typescript
+method?: ValueSuggestionsMethod;
+```
diff --git a/src/plugins/data/common/constants.ts b/src/plugins/data/common/constants.ts
index c6bfbfc75c29..645de0f9fed1 100644
--- a/src/plugins/data/common/constants.ts
+++ b/src/plugins/data/common/constants.ts
@@ -12,6 +12,8 @@ export const KIBANA_USER_QUERY_LANGUAGE_KEY = 'kibana.userQueryLanguage';
/** @public **/
export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern';
+export type ValueSuggestionsMethod = 'terms_enum' | 'terms_agg';
+
export const UI_SETTINGS = {
META_FIELDS: 'metaFields',
DOC_HIGHLIGHT: 'doc_table:highlight',
diff --git a/src/plugins/data/public/autocomplete/providers/kql_query_suggestion/value.ts b/src/plugins/data/public/autocomplete/providers/kql_query_suggestion/value.ts
index f8fc9d165fc6..cee7d37a1a12 100644
--- a/src/plugins/data/public/autocomplete/providers/kql_query_suggestion/value.ts
+++ b/src/plugins/data/public/autocomplete/providers/kql_query_suggestion/value.ts
@@ -35,7 +35,7 @@ export const setupGetValueSuggestions: KqlQuerySuggestionProvider = (
.getStartServices()
.then(([_, __, dataStart]) => dataStart.autocomplete);
return async (
- { indexPatterns, boolFilter, useTimeRange, signal },
+ { indexPatterns, boolFilter, useTimeRange, signal, method },
{ start, end, prefix, suffix, fieldName, nestedPath }
): Promise => {
const fullFieldName = nestedPath ? `${nestedPath}.${fieldName}` : fieldName;
@@ -59,6 +59,7 @@ export const setupGetValueSuggestions: KqlQuerySuggestionProvider = (
boolFilter,
useTimeRange,
signal,
+ method,
}).then((valueSuggestions) => {
const quotedValues = valueSuggestions.map((value) =>
typeof value === 'string' ? `"${escapeQuotes(value)}"` : `${value}`
diff --git a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts
index 449b056a60c7..ebd90c7e92d7 100644
--- a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts
+++ b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts
@@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
+import { ValueSuggestionsMethod } from '../../../common';
import { IFieldType, IIndexPattern } from '../../../common/index_patterns';
export enum QuerySuggestionTypes {
@@ -30,6 +31,7 @@ export interface QuerySuggestionGetFnArgs {
signal?: AbortSignal;
useTimeRange?: boolean;
boolFilter?: any;
+ method?: ValueSuggestionsMethod;
}
/** @public **/
diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
index 3dda97566da5..05dc38b8e5ac 100644
--- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
+++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
@@ -9,7 +9,13 @@
import dateMath from '@elastic/datemath';
import { memoize } from 'lodash';
import { CoreSetup } from 'src/core/public';
-import { IIndexPattern, IFieldType, UI_SETTINGS, buildQueryFromFilters } from '../../../common';
+import {
+ IIndexPattern,
+ IFieldType,
+ UI_SETTINGS,
+ buildQueryFromFilters,
+ ValueSuggestionsMethod,
+} from '../../../common';
import { TimefilterSetup } from '../../query';
import { AutocompleteUsageCollector } from '../collectors';
@@ -22,6 +28,7 @@ interface ValueSuggestionsGetFnArgs {
useTimeRange?: boolean;
boolFilter?: any[];
signal?: AbortSignal;
+ method?: ValueSuggestionsMethod;
}
const getAutocompleteTimefilter = (
@@ -54,12 +61,25 @@ export const setupValueSuggestionProvider = (
}
const requestSuggestions = memoize(
- (index: string, field: IFieldType, query: string, filters: any = [], signal?: AbortSignal) => {
+ (
+ index: string,
+ field: IFieldType,
+ query: string,
+ filters: any = [],
+ signal?: AbortSignal,
+ method?: ValueSuggestionsMethod
+ ) => {
usageCollector?.trackRequest();
return core.http
.fetch(`/api/kibana/suggestions/values/${index}`, {
method: 'POST',
- body: JSON.stringify({ query, field: field.name, fieldMeta: field?.toSpec?.(), filters }),
+ body: JSON.stringify({
+ query,
+ field: field.name,
+ fieldMeta: field?.toSpec?.(),
+ filters,
+ method,
+ }),
signal,
})
.then((r) => {
@@ -77,6 +97,7 @@ export const setupValueSuggestionProvider = (
useTimeRange,
boolFilter,
signal,
+ method,
}: ValueSuggestionsGetFnArgs): Promise => {
const shouldSuggestValues = core!.uiSettings.get(
UI_SETTINGS.FILTERS_EDITOR_SUGGEST_VALUES
@@ -98,7 +119,7 @@ export const setupValueSuggestionProvider = (
const filters = [...(boolFilter ? boolFilter : []), ...filterQuery];
try {
usageCollector?.trackCall();
- return await requestSuggestions(title, field, query, filters, signal);
+ return await requestSuggestions(title, field, query, filters, signal, method);
} catch (e) {
if (!signal?.aborted) {
usageCollector?.trackError();
diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md
index 6c0ddd000f30..4508ad594892 100644
--- a/src/plugins/data/public/public.api.md
+++ b/src/plugins/data/public/public.api.md
@@ -2178,6 +2178,10 @@ export interface QuerySuggestionGetFnArgs {
indexPatterns: IIndexPattern[];
// (undocumented)
language: string;
+ // Warning: (ae-forgotten-export) The symbol "ValueSuggestionsMethod" needs to be exported by the entry point index.d.ts
+ //
+ // (undocumented)
+ method?: ValueSuggestionsMethod;
// (undocumented)
query: string;
// (undocumented)
diff --git a/src/plugins/data/server/autocomplete/value_suggestions_route.ts b/src/plugins/data/server/autocomplete/value_suggestions_route.ts
index bd622d0151c9..42f2c4d4e634 100644
--- a/src/plugins/data/server/autocomplete/value_suggestions_route.ts
+++ b/src/plugins/data/server/autocomplete/value_suggestions_route.ts
@@ -33,6 +33,9 @@ export function registerValueSuggestionsRoute(router: IRouter, config$: Observab
query: schema.string(),
filters: schema.maybe(schema.any()),
fieldMeta: schema.maybe(schema.any()),
+ method: schema.maybe(
+ schema.oneOf([schema.literal('terms_agg'), schema.literal('terms_enum')])
+ ),
},
{ unknowns: 'allow' }
),
@@ -40,13 +43,13 @@ export function registerValueSuggestionsRoute(router: IRouter, config$: Observab
},
async (context, request, response) => {
const config = await config$.pipe(first()).toPromise();
- const { field: fieldName, query, filters, fieldMeta } = request.body;
+ const { field: fieldName, query, filters, fieldMeta, method } = request.body;
const { index } = request.params;
const abortSignal = getRequestAbortedSignal(request.events.aborted$);
try {
const fn =
- config.autocomplete.valueSuggestions.method === 'terms_enum'
+ (method ?? config.autocomplete.valueSuggestions.method) === 'terms_enum'
? termsEnumSuggestions
: termsAggSuggestions;
const body = await fn(
diff --git a/x-pack/plugins/apm/server/utils/queries.test.ts b/x-pack/plugins/apm/common/utils/environment_query.test.ts
similarity index 80%
rename from x-pack/plugins/apm/server/utils/queries.test.ts
rename to x-pack/plugins/apm/common/utils/environment_query.test.ts
index 9fa97940db8f..a4ffec0d64d3 100644
--- a/x-pack/plugins/apm/server/utils/queries.test.ts
+++ b/x-pack/plugins/apm/common/utils/environment_query.test.ts
@@ -5,9 +5,9 @@
* 2.0.
*/
-import { SERVICE_ENVIRONMENT } from '../../common/elasticsearch_fieldnames';
-import { ENVIRONMENT_NOT_DEFINED } from '../../common/environment_filter_values';
-import { environmentQuery } from './queries';
+import { SERVICE_ENVIRONMENT } from '../elasticsearch_fieldnames';
+import { ENVIRONMENT_NOT_DEFINED } from '../environment_filter_values';
+import { environmentQuery } from './environment_query';
describe('environmentQuery', () => {
describe('when environment is undefined', () => {
diff --git a/x-pack/plugins/apm/server/utils/queries.ts b/x-pack/plugins/apm/common/utils/environment_query.ts
similarity index 68%
rename from x-pack/plugins/apm/server/utils/queries.ts
rename to x-pack/plugins/apm/common/utils/environment_query.ts
index a82b49a84dc6..acc75c13a0e3 100644
--- a/x-pack/plugins/apm/server/utils/queries.ts
+++ b/x-pack/plugins/apm/common/utils/environment_query.ts
@@ -5,15 +5,12 @@
* 2.0.
*/
-import { ESFilter } from '../../../../../src/core/types/elasticsearch';
-import { SERVICE_ENVIRONMENT } from '../../common/elasticsearch_fieldnames';
+import { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types';
+import { SERVICE_ENVIRONMENT } from '../elasticsearch_fieldnames';
import {
ENVIRONMENT_ALL,
ENVIRONMENT_NOT_DEFINED,
-} from '../../common/environment_filter_values';
-export { kqlQuery, rangeQuery } from '../../../observability/server';
-
-type QueryDslQueryContainer = ESFilter;
+} from '../environment_filter_values';
export function environmentQuery(
environment?: string
diff --git a/x-pack/plugins/apm/public/components/shared/kuery_bar/get_bool_filter.ts b/x-pack/plugins/apm/public/components/shared/kuery_bar/get_bool_filter.ts
index 150a4d9efc2c..50db1db8f38f 100644
--- a/x-pack/plugins/apm/public/components/shared/kuery_bar/get_bool_filter.ts
+++ b/x-pack/plugins/apm/public/components/shared/kuery_bar/get_bool_filter.ts
@@ -14,6 +14,7 @@ import {
TRANSACTION_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
import { UIProcessorEvent } from '../../../../common/processor_event';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { IUrlParams } from '../../../context/url_params_context/types';
export function getBoolFilter({
@@ -35,6 +36,14 @@ export function getBoolFilter({
});
}
+ boolFilter.push(...environmentQuery(urlParams.environment));
+
+ if (urlParams.transactionType) {
+ boolFilter.push({
+ term: { [TRANSACTION_TYPE]: urlParams.transactionType },
+ });
+ }
+
switch (processorEvent) {
case 'transaction':
boolFilter.push({
diff --git a/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx b/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx
index 1b503e9b0528..f56a698885be 100644
--- a/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx
+++ b/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx
@@ -101,6 +101,7 @@ export function KueryBar(props: { prepend?: React.ReactNode | string }) {
selectionStart,
selectionEnd: selectionStart,
useTimeRange: true,
+ method: 'terms_agg',
})) || []
)
.filter((suggestion) => !startsWith(suggestion.text, 'span.'))
diff --git a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_duration.ts b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_duration.ts
index 6ce175fcb836..3a67076201ef 100644
--- a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_duration.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_duration.ts
@@ -13,7 +13,8 @@ import {
TRANSACTION_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { AlertParams } from '../../../routes/alerts/chart_preview';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_count.ts b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_count.ts
index 3d64c63cb204..0ead50c70908 100644
--- a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_count.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_count.ts
@@ -8,7 +8,8 @@
import { SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
import { AlertParams } from '../../../routes/alerts/chart_preview';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
index 0a6a25ad9c53..888c929a2c72 100644
--- a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
@@ -12,7 +12,8 @@ import {
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
import { AlertParams } from '../../../routes/alerts/chart_preview';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import {
diff --git a/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts
index 35c80df2ca31..bdd6b240c4bb 100644
--- a/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts
@@ -28,7 +28,7 @@ import {
SERVICE_NAME,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
-import { environmentQuery } from '../../../server/utils/queries';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
diff --git a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts
index ff202669fe1d..c14675cb9398 100644
--- a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts
@@ -30,7 +30,7 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
import { getDurationFormatter } from '../../../common/utils/formatters';
-import { environmentQuery } from '../../../server/utils/queries';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
diff --git a/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts
index 36fd9c3fac58..a39730265953 100644
--- a/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts
@@ -32,7 +32,7 @@ import {
import { EventOutcome } from '../../../common/event_outcome';
import { ProcessorEvent } from '../../../common/processor_event';
import { asDecimalOrInteger } from '../../../common/utils/formatters';
-import { environmentQuery } from '../../../server/utils/queries';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
index d93514c42bbd..28f3041d65d7 100644
--- a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
+++ b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
@@ -11,7 +11,7 @@ import { snakeCase } from 'lodash';
import Boom from '@hapi/boom';
import { ML_ERRORS } from '../../../common/anomaly_detection';
import { ProcessorEvent } from '../../../common/processor_event';
-import { environmentQuery } from '../../../server/utils/queries';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { Setup } from '../helpers/setup_request';
import {
TRANSACTION_DURATION,
diff --git a/x-pack/plugins/apm/server/lib/correlations/get_filters.ts b/x-pack/plugins/apm/server/lib/correlations/get_filters.ts
index 61fec492ad38..d6e8f3f57c91 100644
--- a/x-pack/plugins/apm/server/lib/correlations/get_filters.ts
+++ b/x-pack/plugins/apm/server/lib/correlations/get_filters.ts
@@ -7,7 +7,8 @@
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { ESFilter } from '../../../../../../src/core/types/elasticsearch';
-import { environmentQuery, rangeQuery, kqlQuery } from '../../utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import {
SERVICE_NAME,
TRANSACTION_NAME,
diff --git a/x-pack/plugins/apm/server/lib/environments/get_environments.ts b/x-pack/plugins/apm/server/lib/environments/get_environments.ts
index c0b267f18001..84448b1c7c2b 100644
--- a/x-pack/plugins/apm/server/lib/environments/get_environments.ts
+++ b/x-pack/plugins/apm/server/lib/environments/get_environments.ts
@@ -11,7 +11,7 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
import { ProcessorEvent } from '../../../common/processor_event';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/errors/distribution/get_buckets.ts b/x-pack/plugins/apm/server/lib/errors/distribution/get_buckets.ts
index fa73ce8f2bc8..48bdfd84b044 100644
--- a/x-pack/plugins/apm/server/lib/errors/distribution/get_buckets.ts
+++ b/x-pack/plugins/apm/server/lib/errors/distribution/get_buckets.ts
@@ -11,11 +11,8 @@ import {
SERVICE_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
export async function getBuckets({
diff --git a/x-pack/plugins/apm/server/lib/errors/get_error_group_sample.ts b/x-pack/plugins/apm/server/lib/errors/get_error_group_sample.ts
index a915a4fb0330..1a05f55dc8de 100644
--- a/x-pack/plugins/apm/server/lib/errors/get_error_group_sample.ts
+++ b/x-pack/plugins/apm/server/lib/errors/get_error_group_sample.ts
@@ -12,11 +12,8 @@ import {
TRANSACTION_SAMPLED,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getTransaction } from '../transactions/get_transaction';
diff --git a/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts b/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts
index 60ce36a85235..d1174fcfcac6 100644
--- a/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts
+++ b/x-pack/plugins/apm/server/lib/helpers/aggregated_transactions/index.ts
@@ -6,7 +6,7 @@
*/
import { SearchAggregatedTransactionSetting } from '../../../../common/aggregated_transactions';
-import { kqlQuery, rangeQuery } from '../../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
import { ProcessorEvent } from '../../../../common/processor_event';
import {
TRANSACTION_DURATION,
diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_service_count.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_service_count.ts
index 086516371387..7bd46bfaabdd 100644
--- a/x-pack/plugins/apm/server/lib/observability_overview/get_service_count.ts
+++ b/x-pack/plugins/apm/server/lib/observability_overview/get_service_count.ts
@@ -6,7 +6,7 @@
*/
import { ProcessorEvent } from '../../../common/processor_event';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts
index 016cb50566da..c74e910e8cd2 100644
--- a/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts
+++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts
@@ -10,7 +10,7 @@ import {
TRANSACTION_REQUEST,
} from '../../../common/transaction_types';
import { TRANSACTION_TYPE } from '../../../common/elasticsearch_fieldnames';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { calculateThroughput } from '../helpers/calculate_throughput';
diff --git a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts
index fc5da4ec1d0f..28fab3369b1e 100644
--- a/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts
+++ b/x-pack/plugins/apm/server/lib/rum_client/has_rum_data.ts
@@ -11,7 +11,7 @@ import {
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { TRANSACTION_PAGE_LOAD } from '../../../common/transaction_types';
export async function hasRumData({
diff --git a/x-pack/plugins/apm/server/lib/rum_client/ui_filters/get_es_filter.ts b/x-pack/plugins/apm/server/lib/rum_client/ui_filters/get_es_filter.ts
index 48beb9bca524..5f587f82e979 100644
--- a/x-pack/plugins/apm/server/lib/rum_client/ui_filters/get_es_filter.ts
+++ b/x-pack/plugins/apm/server/lib/rum_client/ui_filters/get_es_filter.ts
@@ -11,7 +11,7 @@ import {
} from '../../../../common/ux_ui_filter';
import { ESFilter } from '../../../../../../../src/core/types/elasticsearch';
import { UxUIFilters } from '../../../../typings/ui_filters';
-import { environmentQuery } from '../../../utils/queries';
+import { environmentQuery } from '../../../../common/utils/environment_query';
export function getEsFilter(uiFilters: UxUIFilters, exclude?: boolean) {
const localFilterValues = uiFilters;
diff --git a/x-pack/plugins/apm/server/lib/search_strategies/correlations/get_query_with_params.ts b/x-pack/plugins/apm/server/lib/search_strategies/correlations/get_query_with_params.ts
index e0ddfc1b053b..5d4af3e80f8b 100644
--- a/x-pack/plugins/apm/server/lib/search_strategies/correlations/get_query_with_params.ts
+++ b/x-pack/plugins/apm/server/lib/search_strategies/correlations/get_query_with_params.ts
@@ -5,19 +5,16 @@
* 2.0.
*/
-import { pipe } from 'fp-ts/lib/pipeable';
+import type { estypes } from '@elastic/elasticsearch';
import { getOrElse } from 'fp-ts/lib/Either';
-import { failure } from 'io-ts/lib/PathReporter';
+import { pipe } from 'fp-ts/lib/pipeable';
import * as t from 'io-ts';
-
-import type { estypes } from '@elastic/elasticsearch';
+import { failure } from 'io-ts/lib/PathReporter';
import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames';
import type { SearchServiceParams } from '../../../../common/search_strategies/correlations/types';
import { rangeRt } from '../../../routes/default_api_types';
-
-import { Setup, SetupTimeRange } from '../../helpers/setup_request';
-
import { getCorrelationsFilters } from '../../correlations/get_filters';
+import { Setup, SetupTimeRange } from '../../helpers/setup_request';
const getPercentileThresholdValueQuery = (
percentileThresholdValue: number | undefined
diff --git a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts
index 6ecfe425dc8c..8a934a102556 100644
--- a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts
@@ -5,7 +5,7 @@
* 2.0.
*/
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { ProcessorEvent } from '../../../common/processor_event';
import { TRACE_ID } from '../../../common/elasticsearch_fieldnames';
import {
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts
index 7ac56bcd9192..7ce4af41f4fe 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts
@@ -18,7 +18,7 @@ import {
TRANSACTION_PAGE_LOAD,
TRANSACTION_REQUEST,
} from '../../../common/transaction_types';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { withApmSpan } from '../../utils/with_apm_span';
import { getMlJobsWithAPMGroup } from '../anomaly_detection/get_ml_jobs_with_apm_group';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
index 6d50023d3fd0..5fc022508d0a 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
@@ -15,7 +15,7 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { getServicesProjection } from '../../projections/services';
import { mergeProjection } from '../../projections/util/merge_projection';
-import { environmentQuery } from '../../../server/utils/queries';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { withApmSpan } from '../../utils/with_apm_span';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import {
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
index 2e0ac303e515..f9af5d227a86 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
@@ -19,7 +19,8 @@ import {
TRANSACTION_PAGE_LOAD,
TRANSACTION_REQUEST,
} from '../../../common/transaction_types';
-import { environmentQuery, rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { withApmSpan } from '../../utils/with_apm_span';
import {
getDocumentTypeFilterForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts b/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts
index 26d7d2d1ee31..c97bfc1cfacc 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts
@@ -17,7 +17,8 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
import { SERVICE_MAP_TIMEOUT_ERROR } from '../../../common/service_map';
-import { environmentQuery, rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
const MAX_TRACES_TO_INSPECT = 1000;
diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
index 08587217980f..7a36817dfc45 100644
--- a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
+++ b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
@@ -12,7 +12,8 @@ import {
SERVICE_NAME,
SERVICE_VERSION,
} from '../../../../common/elasticsearch_fieldnames';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
index 56b7aa1f465b..1e8b52814293 100644
--- a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
+++ b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
@@ -7,7 +7,8 @@
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { ElasticsearchClient, Logger } from 'kibana/server';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import {
unwrapEsResponse,
WrappedElasticsearchClientError,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_agent_name.ts b/x-pack/plugins/apm/server/lib/services/get_service_agent_name.ts
index 82147d7c9423..49489f2b3388 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_agent_name.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_agent_name.ts
@@ -10,7 +10,7 @@ import {
AGENT_NAME,
SERVICE_NAME,
} from '../../../common/elasticsearch_fieldnames';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_alerts.ts b/x-pack/plugins/apm/server/lib/services/get_service_alerts.ts
index 2141570f521c..a9fe55456ad4 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_alerts.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_alerts.ts
@@ -11,7 +11,8 @@ import {
SERVICE_NAME,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
-import { environmentQuery, rangeQuery } from '../../utils/queries';
+import { rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
export async function getServiceAlerts({
ruleDataClient,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_destination_map.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_destination_map.ts
index 4993484f5b24..8382ff820805 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_destination_map.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_destination_map.ts
@@ -21,7 +21,8 @@ import {
SPAN_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { joinByKey } from '../../../../common/utils/join_by_key';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { withApmSpan } from '../../../utils/with_apm_span';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_metrics.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_metrics.ts
index 1d815dd7180e..52d3b41960a5 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_metrics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/get_metrics.ts
@@ -14,7 +14,8 @@ import {
SPAN_DESTINATION_SERVICE_RESPONSE_TIME_SUM,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
-import { environmentQuery, rangeQuery } from '../../../../server/utils/queries';
+import { environmentQuery } from '../../../../common/utils/environment_query';
+import { rangeQuery } from '../../../../../observability/server';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { EventOutcome } from '../../../../common/event_outcome';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_detailed_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_detailed_statistics.ts
index bd69bfc53db7..1e0c8e6f6044 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_detailed_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_detailed_statistics.ts
@@ -13,11 +13,8 @@ import {
TRANSACTION_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_main_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_main_statistics.ts
index 8168c0d5549a..9922cbce83df 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_main_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/get_service_error_group_main_statistics.ts
@@ -14,11 +14,8 @@ import {
} from '../../../../common/elasticsearch_fieldnames';
import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n';
import { ProcessorEvent } from '../../../../common/processor_event';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getErrorName } from '../../helpers/get_error_name';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/index.ts
index b720c56464c3..0e9f8282301b 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_error_groups/index.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_error_groups/index.ts
@@ -9,11 +9,8 @@ import { ValuesType } from 'utility-types';
import { orderBy } from 'lodash';
import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n';
import { PromiseReturnType } from '../../../../../observability/typings/common';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { ProcessorEvent } from '../../../../common/processor_event';
import {
ERROR_EXC_MESSAGE,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instance_metadata_details.ts b/x-pack/plugins/apm/server/lib/services/get_service_instance_metadata_details.ts
index bdf9530a9c0c..44dfc2f600ef 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_instance_metadata_details.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_instance_metadata_details.ts
@@ -10,7 +10,8 @@ import {
SERVICE_NODE_NAME,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
-import { environmentQuery, kqlQuery, rangeQuery } from '../../utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_system_metric_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_system_metric_statistics.ts
index b817d4fb654c..48209d98e86c 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_system_metric_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_system_metric_statistics.ts
@@ -17,7 +17,8 @@ import {
import { ProcessorEvent } from '../../../../common/processor_event';
import { SERVICE_NODE_NAME_MISSING } from '../../../../common/service_nodes';
import { Coordinate } from '../../../../typings/timeseries';
-import { environmentQuery, kqlQuery, rangeQuery } from '../../../utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { Setup } from '../../helpers/setup_request';
import {
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_transaction_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_transaction_statistics.ts
index 6110ad345991..d0f58ee8be31 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_transaction_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instances_transaction_statistics.ts
@@ -14,7 +14,8 @@ import { EventOutcome } from '../../../../common/event_outcome';
import { LatencyAggregationType } from '../../../../common/latency_aggregation_types';
import { SERVICE_NODE_NAME_MISSING } from '../../../../common/service_nodes';
import { Coordinate } from '../../../../typings/timeseries';
-import { environmentQuery, kqlQuery, rangeQuery } from '../../../utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_metadata_details.ts b/x-pack/plugins/apm/server/lib/services/get_service_metadata_details.ts
index 910725b00541..60b0628017ef 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_metadata_details.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_metadata_details.ts
@@ -20,7 +20,7 @@ import {
SERVICE_VERSION,
} from '../../../common/elasticsearch_fieldnames';
import { ContainerType } from '../../../common/service_metadata';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { TransactionRaw } from '../../../typings/es_schemas/raw/transaction_raw';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_metadata_icons.ts b/x-pack/plugins/apm/server/lib/services/get_service_metadata_icons.ts
index 469c788a6cf1..ce9a9f59d0e2 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_metadata_icons.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_metadata_icons.ts
@@ -16,7 +16,7 @@ import {
HOST_OS_PLATFORM,
} from '../../../common/elasticsearch_fieldnames';
import { ContainerType } from '../../../common/service_metadata';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { TransactionRaw } from '../../../typings/es_schemas/raw/transaction_raw';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts
index ea33c942cfc3..6edec60b6f37 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts
@@ -15,11 +15,8 @@ import {
import { EventOutcome } from '../../../common/event_outcome';
import { LatencyAggregationType } from '../../../common/latency_aggregation_types';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups.ts
index a4cc27c875d7..223abf972ee2 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups.ts
@@ -13,11 +13,8 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { EventOutcome } from '../../../common/event_outcome';
import { LatencyAggregationType } from '../../../common/latency_aggregation_types';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_types.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_types.ts
index f38a7fba09d9..8d5a9248abce 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_types.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_types.ts
@@ -9,7 +9,7 @@ import {
SERVICE_NAME,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import {
getDocumentTypeFilterForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts
index f33bedb6ef4f..cf8b83464b6d 100644
--- a/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_services/get_legacy_data_status.ts
@@ -5,7 +5,7 @@
* 2.0.
*/
-import { rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
import { ProcessorEvent } from '../../../../common/processor_event';
import { OBSERVER_VERSION_MAJOR } from '../../../../common/elasticsearch_fieldnames';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
index 7f48c591521e..c2121dbba97e 100644
--- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
@@ -15,11 +15,8 @@ import {
TRANSACTION_PAGE_LOAD,
TRANSACTION_REQUEST,
} from '../../../../common/transaction_types';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
import {
getDocumentTypeFilterForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_services_from_metric_documents.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_services_from_metric_documents.ts
index 4692d1122b16..a3bab48646eb 100644
--- a/x-pack/plugins/apm/server/lib/services/get_services/get_services_from_metric_documents.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_services/get_services_from_metric_documents.ts
@@ -11,7 +11,8 @@ import {
SERVICE_ENVIRONMENT,
SERVICE_NAME,
} from '../../../../common/elasticsearch_fieldnames';
-import { environmentQuery, kqlQuery, rangeQuery } from '../../../utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { ProcessorEvent } from '../../../../common/processor_event';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts
index 7eacf47f15b7..4004d55da79f 100644
--- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts
@@ -10,11 +10,8 @@ import {
SERVICE_NAME,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_statistics.ts b/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_statistics.ts
index 4e88c752aa50..4434cc89d24f 100644
--- a/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_statistics.ts
+++ b/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_statistics.ts
@@ -21,11 +21,8 @@ import {
PROFILE_TOP_ID,
SERVICE_NAME,
} from '../../../../common/elasticsearch_fieldnames';
-import {
- rangeQuery,
- environmentQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { APMEventClient } from '../../helpers/create_es_client/create_apm_event_client';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { withApmSpan } from '../../../utils/with_apm_span';
diff --git a/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_timeline.ts b/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_timeline.ts
index af3cd6596a8c..19de91a5a105 100644
--- a/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_timeline.ts
+++ b/x-pack/plugins/apm/server/lib/services/profiling/get_service_profiling_timeline.ts
@@ -5,7 +5,6 @@
* 2.0.
*/
import { mapKeys, mapValues } from 'lodash';
-import { rangeQuery, environmentQuery } from '../../../../server/utils/queries';
import { ProcessorEvent } from '../../../../common/processor_event';
import {
PROFILE_ID,
@@ -17,7 +16,8 @@ import {
} from '../../../../common/profiling';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { getBucketSize } from '../../helpers/get_bucket_size';
-import { kqlQuery } from '../../../utils/queries';
+import { environmentQuery } from '../../../../common/utils/environment_query';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
const configMap = mapValues(
mapKeys(ProfilingValueType, (val, key) => val),
diff --git a/x-pack/plugins/apm/server/lib/traces/get_trace_items.ts b/x-pack/plugins/apm/server/lib/traces/get_trace_items.ts
index 68d316ef55df..026cf9dcceb7 100644
--- a/x-pack/plugins/apm/server/lib/traces/get_trace_items.ts
+++ b/x-pack/plugins/apm/server/lib/traces/get_trace_items.ts
@@ -16,7 +16,7 @@ import {
ERROR_LOG_LEVEL,
} from '../../../common/elasticsearch_fieldnames';
import { APMError } from '../../../typings/es_schemas/ui/apm_error';
-import { rangeQuery } from '../../../server/utils/queries';
+import { rangeQuery } from '../../../../observability/server';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { PromiseValueType } from '../../../typings/common';
diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts b/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
index cc3a13ef5c64..b27a54a98373 100644
--- a/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
+++ b/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
@@ -13,11 +13,8 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { EventOutcome } from '../../../common/event_outcome';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../observability/server';
+import { environmentQuery } from '../../../common/utils/environment_query';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts
index 20534a5fa7cb..f5fcb3c2917e 100644
--- a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.ts
@@ -18,11 +18,8 @@ import {
TRANSACTION_BREAKDOWN_COUNT,
} from '../../../../common/elasticsearch_fieldnames';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import { getMetricsDateHistogramParams } from '../../helpers/metrics';
import { MAX_KPIS } from './constants';
import { getVizColorForIndex } from '../../../../common/viz_colors';
diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts
index 6259bb75386f..62c284cd2205 100644
--- a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts
@@ -17,11 +17,8 @@ import {
} from '../../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../../common/processor_event';
import { joinByKey } from '../../../../../common/utils/join_by_key';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../../observability/server';
+import { environmentQuery } from '../../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution_max.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution_max.ts
index f3d4e8f6dd92..34b790a267c8 100644
--- a/x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution_max.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution_max.ts
@@ -15,11 +15,8 @@ import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../../helpers/aggregated_transactions';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
export async function getDistributionMax({
environment,
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_anomaly_data/fetcher.ts b/x-pack/plugins/apm/server/lib/transactions/get_anomaly_data/fetcher.ts
index 558db1793935..95cca0081e5b 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_anomaly_data/fetcher.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_anomaly_data/fetcher.ts
@@ -8,7 +8,7 @@
import { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types';
import { ESSearchResponse } from '../../../../../../../src/core/types/elasticsearch';
import { PromiseReturnType } from '../../../../../observability/typings/common';
-import { rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import { withApmSpan } from '../../../utils/with_apm_span';
import { Setup } from '../../helpers/setup_request';
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_latency_charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_latency_charts/index.ts
index e3f59ca2e432..183a754ea080 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_latency_charts/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_latency_charts/index.ts
@@ -14,11 +14,8 @@ import {
} from '../../../../common/elasticsearch_fieldnames';
import { LatencyAggregationType } from '../../../../common/latency_aggregation_types';
import { offsetPreviousPeriodCoordinates } from '../../../../common/utils/offset_previous_period_coordinate';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
index ff3534159d19..d5fff2049628 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
@@ -13,11 +13,8 @@ import {
TRANSACTION_RESULT,
TRANSACTION_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
-import {
- environmentQuery,
- kqlQuery,
- rangeQuery,
-} from '../../../../server/utils/queries';
+import { kqlQuery, rangeQuery } from '../../../../../observability/server';
+import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts
index c928b00cefb6..87d205f2bcd1 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_transaction/index.ts
@@ -9,7 +9,7 @@ import {
TRACE_ID,
TRANSACTION_ID,
} from '../../../../common/elasticsearch_fieldnames';
-import { rangeQuery } from '../../../../server/utils/queries';
+import { rangeQuery } from '../../../../../observability/server';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { ProcessorEvent } from '../../../../common/processor_event';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
diff --git a/x-pack/plugins/apm/server/projections/errors.ts b/x-pack/plugins/apm/server/projections/errors.ts
index 341c7d13936b..8f32dd9e5be5 100644
--- a/x-pack/plugins/apm/server/projections/errors.ts
+++ b/x-pack/plugins/apm/server/projections/errors.ts
@@ -10,11 +10,8 @@ import {
SERVICE_NAME,
ERROR_GROUP_ID,
} from '../../common/elasticsearch_fieldnames';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../observability/server';
+import { environmentQuery } from '../../common/utils/environment_query';
import { ProcessorEvent } from '../../common/processor_event';
export function getErrorGroupsProjection({
diff --git a/x-pack/plugins/apm/server/projections/metrics.ts b/x-pack/plugins/apm/server/projections/metrics.ts
index 9a757893337e..54bc498007cb 100644
--- a/x-pack/plugins/apm/server/projections/metrics.ts
+++ b/x-pack/plugins/apm/server/projections/metrics.ts
@@ -11,11 +11,8 @@ import {
SERVICE_NAME,
SERVICE_NODE_NAME,
} from '../../common/elasticsearch_fieldnames';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../observability/server';
+import { environmentQuery } from '../../common/utils/environment_query';
import { SERVICE_NODE_NAME_MISSING } from '../../common/service_nodes';
import { ProcessorEvent } from '../../common/processor_event';
diff --git a/x-pack/plugins/apm/server/projections/rum_page_load_transactions.ts b/x-pack/plugins/apm/server/projections/rum_page_load_transactions.ts
index ae8bb4a5f11a..b8cf92f15c70 100644
--- a/x-pack/plugins/apm/server/projections/rum_page_load_transactions.ts
+++ b/x-pack/plugins/apm/server/projections/rum_page_load_transactions.ts
@@ -11,7 +11,7 @@ import {
TRANSACTION_TYPE,
SERVICE_LANGUAGE_NAME,
} from '../../common/elasticsearch_fieldnames';
-import { rangeQuery } from '../../server/utils/queries';
+import { rangeQuery } from '../../../observability/server';
import { ProcessorEvent } from '../../common/processor_event';
import { TRANSACTION_PAGE_LOAD } from '../../common/transaction_types';
import { getEsFilter } from '../lib/rum_client/ui_filters/get_es_filter';
diff --git a/x-pack/plugins/apm/server/projections/services.ts b/x-pack/plugins/apm/server/projections/services.ts
index 3509e4fa5b33..52992f16dac8 100644
--- a/x-pack/plugins/apm/server/projections/services.ts
+++ b/x-pack/plugins/apm/server/projections/services.ts
@@ -7,7 +7,7 @@
import { Setup, SetupTimeRange } from '../../server/lib/helpers/setup_request';
import { SERVICE_NAME } from '../../common/elasticsearch_fieldnames';
-import { rangeQuery, kqlQuery } from '../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../observability/server';
import { ProcessorEvent } from '../../common/processor_event';
import { getProcessorEventForAggregatedTransactions } from '../lib/helpers/aggregated_transactions';
diff --git a/x-pack/plugins/apm/server/projections/transactions.ts b/x-pack/plugins/apm/server/projections/transactions.ts
index 3e830403debb..1efd9679cae9 100644
--- a/x-pack/plugins/apm/server/projections/transactions.ts
+++ b/x-pack/plugins/apm/server/projections/transactions.ts
@@ -12,11 +12,8 @@ import {
TRANSACTION_TYPE,
TRANSACTION_NAME,
} from '../../common/elasticsearch_fieldnames';
-import {
- environmentQuery,
- rangeQuery,
- kqlQuery,
-} from '../../server/utils/queries';
+import { rangeQuery, kqlQuery } from '../../../observability/server';
+import { environmentQuery } from '../../common/utils/environment_query';
import {
getProcessorEventForAggregatedTransactions,
getDocumentTypeFilterForAggregatedTransactions,