Skip to content

Commit

Permalink
[Chore] Rename field_caps filter-param to indexFilter (#147480)
Browse files Browse the repository at this point in the history
Field-caps API
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html
has an `index_filter` param, which Kibana is calling `filter`.

Renaming to `indexFilter` for consistency, to avoid confusion.

Main reason for putting up this PR was to help identify usage of
`index_filter`-param of field-caps in the code-base.
  • Loading branch information
thomasneirynck authored Dec 14, 2022
1 parent 6a1b37e commit 985e581
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export class DataViewsService {
type: options.type,
rollupIndex: options.rollupIndex,
allowNoIndex: options.allowNoIndex,
filter: options.filter,
indexFilter: options.indexFilter,
});
return fields;
};
Expand Down Expand Up @@ -543,7 +543,7 @@ export class DataViewsService {
type: options.type,
rollupIndex: options.rollupIndex,
allowNoIndex: options.allowNoIndex,
filter: options.filter,
indexFilter: options.indexFilter,
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export interface GetFieldsOptions {
metaFields?: string[];
rollupIndex?: string;
allowNoIndex?: boolean;
filter?: QueryDslQueryContainer;
indexFilter?: QueryDslQueryContainer;
includeUnmapped?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
* @param options options for fields request
*/
getFieldsForWildcard(options: GetFieldsOptions) {
const { pattern, metaFields, type, rollupIndex, allowNoIndex, filter, includeUnmapped } =
const { pattern, metaFields, type, rollupIndex, allowNoIndex, indexFilter, includeUnmapped } =
options;
return this._request<FieldsForWildcardResponse>(
this._getUrl(['_fields_for_wildcard']),
Expand All @@ -61,7 +61,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
allow_no_index: allowNoIndex,
include_unmapped: includeUnmapped,
},
filter ? JSON.stringify({ index_filter: filter }) : undefined
indexFilter ? JSON.stringify({ index_filter: indexFilter }) : undefined
).then((response) => {
return response || { fields: [], indices: [] };
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class IndexPatternsFetcher {
fieldCapsOptions?: { allow_no_indices: boolean; includeUnmapped?: boolean };
type?: string;
rollupIndex?: string;
filter?: QueryDslQueryContainer;
indexFilter?: QueryDslQueryContainer;
}): Promise<{ fields: FieldDescriptor[]; indices: string[] }> {
const { pattern, metaFields = [], fieldCapsOptions, type, rollupIndex, filter } = options;
const { pattern, metaFields = [], fieldCapsOptions, type, rollupIndex, indexFilter } = options;
const patternList = Array.isArray(pattern) ? pattern : pattern.split(',');
const allowNoIndices = fieldCapsOptions
? fieldCapsOptions.allow_no_indices
Expand All @@ -80,7 +80,7 @@ export class IndexPatternsFetcher {
allow_no_indices: allowNoIndices,
include_unmapped: fieldCapsOptions?.includeUnmapped,
},
filter,
indexFilter,
});
if (type === 'rollup' && rollupIndex) {
const rollupFields: FieldDescriptor[] = [];
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data_views/server/fetcher/lib/es_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface FieldCapsApiParams {
callCluster: ElasticsearchClient;
indices: string[] | string;
fieldCapsOptions?: { allow_no_indices: boolean; include_unmapped?: boolean };
filter?: QueryDslQueryContainer;
indexFilter?: QueryDslQueryContainer;
}

/**
Expand All @@ -62,7 +62,7 @@ export async function callFieldCapsApi(params: FieldCapsApiParams) {
const {
callCluster,
indices,
filter,
indexFilter,
fieldCapsOptions = {
allow_no_indices: false,
include_unmapped: false,
Expand All @@ -74,7 +74,7 @@ export async function callFieldCapsApi(params: FieldCapsApiParams) {
index: indices,
fields: '*',
ignore_unavailable: true,
index_filter: filter,
index_filter: indexFilter,
...fieldCapsOptions,
},
{ meta: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('index_patterns/field_capabilities/field_capabilities', () => {
callCluster: undefined,
indices: undefined,
fieldCapsOptions: undefined,
filter: undefined,
indexFilter: undefined,
...args,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface FieldCapabilitiesParams {
indices: string | string[];
metaFields: string[];
fieldCapsOptions?: { allow_no_indices: boolean; include_unmapped?: boolean };
filter?: QueryDslQueryContainer;
indexFilter?: QueryDslQueryContainer;
}

/**
Expand All @@ -34,8 +34,13 @@ interface FieldCapabilitiesParams {
* @return {Promise<{ fields: Array<FieldDescriptor>, indices: Array<string>>}>}
*/
export async function getFieldCapabilities(params: FieldCapabilitiesParams) {
const { callCluster, indices = [], fieldCapsOptions, filter, metaFields = [] } = params;
const esFieldCaps = await callFieldCapsApi({ callCluster, indices, fieldCapsOptions, filter });
const { callCluster, indices = [], fieldCapsOptions, indexFilter, metaFields = [] } = params;
const esFieldCaps = await callFieldCapsApi({
callCluster,
indices,
fieldCapsOptions,
indexFilter,
});
const fieldsFromFieldCapsByName = keyBy(readFieldCapsResponse(esFieldCaps.body), 'name');

const allFieldsUnsorted = Object.keys(fieldsFromFieldCapsByName)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data_views/server/index_patterns_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class IndexPatternsApiServer implements IDataViewsApiClient {
type,
rollupIndex,
allowNoIndex,
filter,
indexFilter: indexFilter,
}: GetFieldsOptions) {
const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex);
return await indexPatterns
Expand All @@ -35,7 +35,7 @@ export class IndexPatternsApiServer implements IDataViewsApiClient {
metaFields,
type,
rollupIndex,
filter,
indexFilter,
})
.catch((err) => {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data_views/server/routes/fields_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const handler: RequestHandler<{}, IQuery, IBody> = async (context, request, resp
} = request.query;

// not available to get request
const filter = request.body?.index_filter;
const indexFilter = request.body?.index_filter;

let parsedFields: string[] = [];
try {
Expand All @@ -85,7 +85,7 @@ const handler: RequestHandler<{}, IQuery, IBody> = async (context, request, resp
allow_no_indices: allowNoIndex || false,
includeUnmapped,
},
filter,
indexFilter,
});

return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function fetchFieldExistence({
const existingFieldList = await dataViewsService.getFieldsForIndexPattern(dataView, {
// filled in by data views service
pattern: '',
filter: toQuery(timeFieldName, fromDate, toDate, dslQuery),
indexFilter: toQuery(timeFieldName, fromDate, toDate, dslQuery),
});
return {
indexPatternTitle: dataView.title,
Expand Down

0 comments on commit 985e581

Please sign in to comment.