UNPKG

kibana-123

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

43 lines (36 loc) 1.03 kB
import _ from 'lodash'; import DecorateQueryProvider from 'ui/courier/data_source/_decorate_query'; export default function GetQueryFromUser(es, Private) { let decorateQuery = Private(DecorateQueryProvider); /** * Take text from the user and make it into a query object * @param {text} user's query input * @returns {object} */ return function (text) { function getQueryStringQuery(text) { return decorateQuery({query_string: {query: text}}); } let matchAll = getQueryStringQuery('*'); // If we get an empty object, treat it as a * if (_.isObject(text)) { if (Object.keys(text).length) { return text; } else { return matchAll; } } // Nope, not an object. text = (text || '').trim(); if (text.length === 0) return matchAll; if (text[0] === '{') { try { return JSON.parse(text); } catch (e) { return getQueryStringQuery(text); } } else { return getQueryStringQuery(text); } }; };