Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.3] Fixes error when filters agg filters are a query_string query (#43310) #43372

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ export class QueryBarInputUI extends Component<Props, State> {
};

public componentDidMount() {
const parsedQuery = fromUser(toUser(this.props.query.query));
if (!isEqual(this.props.query.query, parsedQuery)) {
this.onChange({ ...this.props.query, query: parsedQuery });
}

this.persistedLog = this.props.persistedLog
? this.props.persistedLog
: getQueryLog(this.props.appName, this.props.query.language);
Expand All @@ -397,6 +402,11 @@ export class QueryBarInputUI extends Component<Props, State> {
}

public componentDidUpdate(prevProps: Props) {
const parsedQuery = fromUser(toUser(this.props.query.query));
if (!isEqual(this.props.query.query, parsedQuery)) {
this.onChange({ ...this.props.query, query: parsedQuery });
}

this.persistedLog = this.props.persistedLog
? this.props.persistedLog
: getQueryLog(this.props.appName, this.props.query.language);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export function fromUser(userInput: object | string) {
const matchAll = '';

if (_.isObject(userInput)) {
// If we get an empty object, treat it as a *
if (!Object.keys(userInput).length) {
return matchAll;
}
return userInput;
}

Expand Down
38 changes: 38 additions & 0 deletions src/legacy/core_plugins/kibana/migrations/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,39 @@ function replaceMovAvgToMovFn(doc, logger) {
return doc;
}

function migrateFiltersAggQueryStringQueries(doc) {
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
try {
const visState = JSON.parse(visStateJSON);
if (visState && visState.aggs) {
visState.aggs.forEach(agg => {
if (agg.type !== 'filters') return doc;

agg.params.filters.forEach(filter => {
if (filter.input.query.query_string) {
filter.input.query = filter.input.query.query_string.query;
}
});
});

return {
...doc,
attributes: {
...doc.attributes,
visState: JSON.stringify(visState),
},
};
}
} catch (e) {
// Let it go, the data is invalid and we'll leave it as is
}
}
return doc;

}

const executeMigrations720 = flow(
migratePercentileRankAggregation,
migrateDateHistogramAggregation
Expand All @@ -376,6 +409,10 @@ const executeMigrations730 = flow(
replaceMovAvgToMovFn
);

const executeVisualizationMigrations731 = flow(
migrateFiltersAggQueryStringQueries,
);

export const migrations = {
'index-pattern': {
'6.5.0': doc => {
Expand Down Expand Up @@ -481,6 +518,7 @@ export const migrations = {
'7.0.1': removeDateHistogramTimeZones,
'7.2.0': doc => executeMigrations720(doc),
'7.3.0': executeMigrations730,
'7.3.1': executeVisualizationMigrations731,
},
dashboard: {
'7.0.0': doc => {
Expand Down
37 changes: 37 additions & 0 deletions src/legacy/core_plugins/kibana/migrations/migrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,43 @@ Array [
expect(series[0].filter).toEqual(params.series[0].filter);
});
});

describe('7.3.1', () => {
const migrate = migrations.visualization['7.3.1'];

it('should migrate filters agg query string queries', () => {
const state = {
aggs: [
{ type: 'count', params: {} },
{
type: 'filters',
params: {
filters: [{
input: {
query: {
query_string: { query: 'machine.os.keyword:\"win 8\"' }
}
}
}]
}
}
],
};
const expected = {
aggs: [
{ type: 'count', params: {} },
{
type: 'filters',
params: {
filters: [{ input: { query: 'machine.os.keyword:\"win 8\"' } }]
}
}
],
};
const migratedDoc = migrate({ attributes: { visState: JSON.stringify(state) } });
expect(migratedDoc).toEqual({ attributes: { visState: JSON.stringify(expected) } });
});
});
});

describe('dashboard', () => {
Expand Down