mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Make searching saved objects more powerful with query_string (#9870)
* switch to query_string query and only append trailing * when the query is a simple word * swallow 400 errors from query_string query attempt to mimic simple_query_string... > Unlike the regular query_string query, the simple_query_string query will never throw an exception, and discards invalid parts of the query > https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-simple-query-string-query.html * simplify the regexp no grouping required, and matching 1 or more is fine, as this condition isn't met when the searchString is empty
This commit is contained in:
parent
c1ee6559a3
commit
64a03fafd4
2 changed files with 17 additions and 2 deletions
|
@ -37,6 +37,7 @@ uiModules.get('apps/management')
|
|||
const getData = function (filter) {
|
||||
const services = registry.all().map(function (obj) {
|
||||
const service = $injector.get(obj.service);
|
||||
|
||||
return service.find(filter).then(function (data) {
|
||||
return {
|
||||
service: service,
|
||||
|
|
|
@ -78,11 +78,12 @@ export class SavedObjectLoader {
|
|||
*/
|
||||
find(searchString, size = 100) {
|
||||
let body;
|
||||
|
||||
if (searchString) {
|
||||
body = {
|
||||
query: {
|
||||
simple_query_string: {
|
||||
query: searchString + '*',
|
||||
query_string: {
|
||||
query: /^\w+$/.test(searchString) ? `${searchString}*` : searchString,
|
||||
fields: ['title^3', 'description'],
|
||||
default_operator: 'AND'
|
||||
}
|
||||
|
@ -98,6 +99,19 @@ export class SavedObjectLoader {
|
|||
body,
|
||||
size
|
||||
})
|
||||
.catch(err => {
|
||||
// attempt to mimic simple_query_string, swallow formatting error
|
||||
if (err.statusCode === 400) {
|
||||
return {
|
||||
hits: {
|
||||
total: 0,
|
||||
hits: [],
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
throw err;
|
||||
})
|
||||
.then((resp) => {
|
||||
return {
|
||||
total: resp.hits.total,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue