Skip to content

Commit

Permalink
[data views] Support include_unmapped in field caps request (#146953)
Browse files Browse the repository at this point in the history
## Summary

Allows data views API `getFieldsForWildcard` to support
`include_unmapped` param.

Closes #144772
  • Loading branch information
mattkime authored Dec 6, 2022
1 parent 556d2a4 commit bf103ef
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pageLoadAssetSize:
dataViewEditor: 12000
dataViewFieldEditor: 27000
dataViewManagement: 5000
dataViews: 46600
dataViews: 47000
dataVisualizer: 27530
devTools: 38637
discover: 99999
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export interface GetFieldsOptions {
rollupIndex?: string;
allowNoIndex?: boolean;
filter?: QueryDslQueryContainer;
includeUnmapped?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class DataViewsApiClient implements IDataViewsApiClient {
* @param options options for fields request
*/
getFieldsForWildcard(options: GetFieldsOptions) {
const { pattern, metaFields, type, rollupIndex, allowNoIndex, filter } = options;
const { pattern, metaFields, type, rollupIndex, allowNoIndex, filter, includeUnmapped } =
options;
return this._request<FieldsForWildcardResponse>(
this._getUrl(['_fields_for_wildcard']),
{
Expand All @@ -58,6 +59,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
type,
rollup_index: rollupIndex,
allow_no_index: allowNoIndex,
include_unmapped: includeUnmapped,
},
filter ? JSON.stringify({ index_filter: filter }) : undefined
).then((response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class IndexPatternsFetcher {
async getFieldsForWildcard(options: {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: { allow_no_indices: boolean };
fieldCapsOptions?: { allow_no_indices: boolean; includeUnmapped?: boolean };
type?: string;
rollupIndex?: string;
filter?: QueryDslQueryContainer;
Expand All @@ -78,6 +78,7 @@ export class IndexPatternsFetcher {
metaFields,
fieldCapsOptions: {
allow_no_indices: allowNoIndices,
include_unmapped: fieldCapsOptions?.includeUnmapped,
},
filter,
});
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data_views/server/fetcher/lib/es_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function callIndexAliasApi(
interface FieldCapsApiParams {
callCluster: ElasticsearchClient;
indices: string[] | string;
fieldCapsOptions?: { allow_no_indices: boolean };
fieldCapsOptions?: { allow_no_indices: boolean; include_unmapped?: boolean };
filter?: QueryDslQueryContainer;
}

Expand All @@ -65,6 +65,7 @@ export async function callFieldCapsApi(params: FieldCapsApiParams) {
filter,
fieldCapsOptions = {
allow_no_indices: false,
include_unmapped: false,
},
} = params;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface FieldCapabilitiesParams {
callCluster: ElasticsearchClient;
indices: string | string[];
metaFields: string[];
fieldCapsOptions?: { allow_no_indices: boolean };
fieldCapsOptions?: { allow_no_indices: boolean; include_unmapped?: boolean };
filter?: QueryDslQueryContainer;
}

Expand Down
4 changes: 4 additions & 0 deletions src/plugins/data_views/server/routes/fields_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface IQuery {
type?: string;
rollup_index?: string;
allow_no_index?: boolean;
include_unmapped?: boolean;
}

const validate: RouteValidatorFullConfig<{}, IQuery, IBody> = {
Expand All @@ -47,6 +48,7 @@ const validate: RouteValidatorFullConfig<{}, IQuery, IBody> = {
type: schema.maybe(schema.string()),
rollup_index: schema.maybe(schema.string()),
allow_no_index: schema.maybe(schema.boolean()),
include_unmapped: schema.maybe(schema.boolean()),
}),
// not available to get request
body: schema.maybe(schema.object({ index_filter: schema.any() })),
Expand All @@ -60,6 +62,7 @@ const handler: RequestHandler<{}, IQuery, IBody> = async (context, request, resp
type,
rollup_index: rollupIndex,
allow_no_index: allowNoIndex,
include_unmapped: includeUnmapped,
} = request.query;

// not available to get request
Expand All @@ -80,6 +83,7 @@ const handler: RequestHandler<{}, IQuery, IBody> = async (context, request, resp
rollupIndex,
fieldCapsOptions: {
allow_no_indices: allowNoIndex || false,
includeUnmapped,
},
filter,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export default function ({ getService }) {
})
.expect(200));

it('accepts include_unmapped param', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
.query({
pattern: '*',
include_unmapped: true,
})
.expect(200));

it('accepts meta_fields query param in string array', () =>
supertest
.get('/api/index_patterns/_fields_for_wildcard')
Expand Down

0 comments on commit bf103ef

Please sign in to comment.