-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add Wildcard ("Contains") filter #16357
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
// Creates an filter where the given field contains the given value | ||
export function buildContainsFilter(field, value, indexPattern) { | ||
const index = indexPattern.id; | ||
const type = 'contains'; | ||
const key = field.name; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to take into account scripted fields, similar to how other filters builders do. |
||
const filter = { | ||
meta: { index, type, key, value }, | ||
}; | ||
filter.query = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing we learned when we were working on adding wildcard support to KQL is that
|
||
wildcard: { | ||
[field.name]: { | ||
value: `*${value}*`, | ||
}, | ||
}, | ||
}; | ||
return filter; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Filter, FilterMeta } from './meta_filter'; | ||
|
||
export type ContainsFilterMeta = FilterMeta & { | ||
params: { | ||
value: string; | ||
}; | ||
}; | ||
|
||
export type ContainsFilter = Filter & { | ||
meta: ContainsFilterMeta; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { EuiFormRow } from '@elastic/eui'; | ||
import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; | ||
import React, { Component } from 'react'; | ||
import { Field } from 'ui/index_patterns'; | ||
import { ValueInputType } from './value_input_type'; | ||
|
||
interface Props { | ||
field?: Field; | ||
value?: string; | ||
onChange: (value: string | number | boolean) => void; | ||
intl: InjectedIntl; | ||
} | ||
|
||
class ContainsValueInputUI extends Component<Props> { | ||
public render() { | ||
return ( | ||
<EuiFormRow | ||
label={this.props.intl.formatMessage({ | ||
id: 'data.filter.filterEditor.valueInputLabel', | ||
defaultMessage: 'Value', | ||
})} | ||
> | ||
<ValueInputType | ||
placeholder={this.props.intl.formatMessage({ | ||
id: 'data.filter.filterEditor.valueInputPlaceholder', | ||
defaultMessage: 'Enter a value', | ||
})} | ||
value={this.props.value} | ||
onChange={this.props.onChange} | ||
type={this.props.field ? this.props.field.type : 'string'} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
} | ||
|
||
export const ContainsValueInput = injectI18n(ContainsValueInputUI); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export async function mapContains(filter) { | ||
const { type, key, value, params } = filter.meta; | ||
if (type !== 'contains') { | ||
throw filter; | ||
} else { | ||
return { type, key, value, params }; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add some unit tests for this function?