/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.lens_bundle_jsonpfunction=window.lens_bundle_jsonpfunction||[]).push([[9],{108:function(e,t,a){"use strict";a.d(t,"a",(function(){return o})),a.d(t,"c",(function(){return r})),a.d(t,"b",(function(){return i}));var n=a(25);const s=["_type","_source"];const o=e=>"_score"!==e.name&&["string","text","keyword","version","ip","number","geo_point","geo_shape"].includes(e.type),r=e=>!e.aggregatable&&o(e)||"geo_point"===e.type||"geo_shape"===e.type;function i(e,t){if(e=Object(n.defaults)(e,{count:5}),!o(e.field))throw new Error(`Analysis is not available this field type: "${e.field.type}". Field name: "${e.field.name}"`);const a=(r=e.hits,i=e.field,u=e.dataView,Object(n.map)(r,(function(e){return function(e,t,a){var o;const r={};function i(e,s=""){for(const[o,u]of Object.entries(e)){const e=s+o,l=null==t?void 0:t.fields.getByName(e);if(!1===(null==a?void 0:a.shallow)){const t="nested"===(null==l?void 0:l.type);if(Array.isArray(u)&&!t){u.forEach((t=>Object(n.isPlainObject)(t)&&i(t,e+".")));continue}}else if(void 0!==r[e])continue;const c=l&&"conflict"!==l.type,m=!Object(n.isPlainObject)(u);c||m?r[e]?Array.isArray(r[e])?r[e].push(u):r[e]=[r[e],u]:r[e]=u:i(u,e+".")}}return i(e.fields||{}),!1!==(null==a?void 0:a.source)&&e._source?i(e._source):null!=a&&a.includeIgnoredValues&&e.ignored_field_values&&Object.entries(e.ignored_field_values).forEach((([e,t])=>{r[e]?Array.isArray(r[e])?r[e]=[...r[e],...t]:r[e]=[r[e],...t]:r[e]=t})),null==t||null===(o=t.metaFields)||void 0===o||o.forEach((t=>{s.includes(t)||"_"!==t.charAt(0)||(r[t]=e[t])})),new Proxy(r,{ownKeys:e=>Reflect.ownKeys(e).sort(((e,a)=>{var n,s;const o=null==t||null===(n=t.metaFields)||void 0===n?void 0:n.includes(String(e)),r=null==t||null===(s=t.metaFields)||void 0===s?void 0:s.includes(String(a));return o&&r?String(e).localeCompare(String(a)):o?1:r?-1:String(e).localeCompare(String(a))}))})}(e,u,{includeIgnoredValues:!0})[i.name]})));var r,i,u;const{groups:l,sampledValues:c}=function(e,t){const a={};let s=0;return e.forEach((function(e){if(Object(n.isObject)(e)&&!Array.isArray(e))throw new Error("Analysis is not available for object fields.");let o,r=0;const i={};o=Array.isArray(e)?e:null==e?[]:[e],o.forEach((e=>{const n=t?t.convert(e):e;i[n]||(a.hasOwnProperty(n)?a[n].count++:a[n]={key:n,count:1,order:r++},i[n]=!0,s++)}))})),{groups:a,sampledValues:s}}(a,t);return{buckets:Object(n.sortBy)(l,["count","order"]).reverse().slice(0,e.count).map((e=>Object(n.pick)(e,["key","count"]))),sampledValues:c,sampledDocuments:e.hits.length}}},136:function(e,t,a){"use strict";a.d(t,"a",(function(){return l})),a.d(t,"d",(function(){return c})),a.d(t,"c",(function(){return d})),a.d(t,"b",(function(){return g}));var n=a(47),s=a.n(n),o=a(108);const r=5e3,i=10,u=100;function l({dataViewPattern:e,timeFieldName:t,fromDate:a,toDate:n,dslQuery:s,runtimeMappings:o,aggs:r,fields:i,size:u}){const l=t?[{range:{[t]:{gte:a,lte:n,format:"strict_date_optional_time"}}},s]:[s];return 1===(null==i?void 0:i.length)&&l.push({exists:i[0]}),{index:e,body:{query:{bool:{filter:l}},aggs:r,fields:i,runtime_mappings:o,_source:(null==i||!i.length)&&void 0},track_total_hits:!0,size:null!=u?u:0}}async function c({searchHandler:e,dataView:t,field:a,fromDate:n,toDate:u,size:l}){return a.aggregatable?"geo_point"===a.type||"geo_shape"===a.type?await async function(e,t,a){try{const n=a.getFormatterForField(t);return await f(e,t,a,n)}catch(e){return console.error(e),{}}}(e,a,t):m(a)?"histogram"===a.type?await p(e,a,!1):g(a)?await async function(e,t){const a={sample:{sampler:{shard_size:r},aggs:{min_max_summary:{filter:{exists:{field:t.name}},aggs:{min:{min:{field:t.name}},max:{max:{field:t.name}}}}}}},n=await e({aggs:a}),s=n.aggregations.sample.min_max_summary.min.value,o=n.aggregations.sample.min_max_summary.max.value,i=n.aggregations.sample.doc_count;return{totalDocuments:y(n),sampledDocuments:i,sampledValues:i,numberSummary:{minValue:s,maxValue:o}}}(e,a):"number"===a.type?await p(e,a):"date"===a.type?await async function(e,t,a){const n=s.a.parse(a.fromDate),o=s.a.parse(a.toDate);if(!n)throw Error("Invalid fromDate value");if(!o)throw Error("Invalid toDate value");const r=Math.round((o.valueOf()-n.valueOf())/10);if(r<1)return{totalDocuments:0,histogram:{buckets:[]}};const i=`${r}ms`,u={histo:{date_histogram:{..._(t),fixed_interval:i}}},l=await e({aggs:u});return{totalDocuments:y(l),histogram:{buckets:l.aggregations.histo.buckets.map((e=>({count:e.doc_count,key:e.key})))}}}(e,a,{fromDate:n,toDate:u}):await async function(e,t,a=i){const n=_(t),s={sample:{sampler:{shard_size:r},aggs:{sample_count:{value_count:{...n}},top_values:{terms:{...n,size:a,shard_size:a<=10?25:void 0}}}}},o=await e({aggs:s}),u={buckets:o.aggregations.sample.top_values.buckets.map((e=>({count:e.doc_count,key:e.key})))};return{totalDocuments:y(o),sampledDocuments:o.aggregations.sample.doc_count,sampledValues:h(u,o.aggregations.sample.top_values.sum_other_doc_count)||o.aggregations.sample.sample_count.value,topValues:u}}(e,a,l):{}:Object(o.a)(a)?await f(e,a,t):{}}function m(e){return!("document"===e.type||e.type.includes("range")||"geo_point"===e.type||"geo_shape"===e.type||"murmur3"===e.type||"attachment"===e.type)}function d(e){return e.aggregatable&&m(e)||Object(o.c)(e)}function g(e){return"counter"===e.timeSeriesMetric}async function p(e,t,a=!0){const n=_(t),s={min_value:{min:{field:t.name}},max_value:{max:{field:t.name}},sample_count:{value_count:{...n}}},o={sample:{sampler:{shard_size:r},aggs:{...s}}},u={sample:{sampler:{shard_size:r},aggs:{...s,top_values:{terms:{...n,size:i}}}}},l=await e({aggs:a?u:o}),c=l.aggregations.sample.min_value.value,m=l.aggregations.sample.max_value.value,d="top_values"in l.aggregations.sample?l.aggregations.sample.top_values:{buckets:[],sum_other_doc_count:0},g={buckets:d.buckets.map((e=>({count:e.doc_count,key:e.key})))};let p=(m-c)/10;if(Number.isInteger(c)&&Number.isInteger(m)&&(p=Math.ceil(p)),0===p)return{totalDocuments:y(l),sampledValues:h(g,d.sum_other_doc_count)||l.aggregations.sample.sample_count.value,sampledDocuments:l.aggregations.sample.doc_count,topValues:g,histogram:a?{buckets:[]}:{buckets:[{count:l.aggregations.sample.doc_count,key:c}]}};const f={sample:{sampler:{shard_size:r},aggs:{histo:{histogram:{field:t.name,interval:p}}}}},v=await e({aggs:f});return{totalDocuments:y(l),sampledDocuments:l.aggregations.sample.doc_count,sampledValues:h(g,d.sum_other_doc_count)||l.aggregations.sample.sample_count.value,histogram:{buckets:v.aggregations.sample.histo.buckets.map((e=>({count:e.doc_count,key:e.key})))},topValues:g}}async function f(e,t,a,n){try{const s=_(t),r={size:u,fields:[s]},l=await e(r),c=Object(o.b)({hits:l.hits.hits,field:t,dataView:a,count:i},n);return{totalDocuments:y(l),sampledDocuments:c.sampledDocuments,sampledValues:c.sampledValues,topValues:{buckets:c.buckets}}}catch(e){return console.error(e),{}}}function _(e){return e.scripted?{script:{lang:e.lang,source:e.script}}:{field:e.name}}const y=e=>{var t,a;return null!==(t=null!==(a=e.hits.total.value)&&void 0!==a?a:e.hits.total)&&void 0!==t?t:0};function h(e,t){var a;return((null==e||null===(a=e.buckets)||void 0===a?void 0:a.reduce(((e,t)=>t.count+e),0))||0)+(t||0)}},537:function(e,t,a){"use strict";a.r(t),a.d(t,"loadFieldStats",(function(){return o}));var n=a(13),s=a(136);const o=async({services:e,dataView:t,field:a,fromDate:o,toDate:r,dslQuery:i,size:u,abortController:l})=>{const{data:c}=e;try{if(null==t||!t.id||null==a||!a.type)return{};const e=async e=>(await Object(n.lastValueFrom)(c.search.search({params:Object(s.a)({dataViewPattern:t.title,timeFieldName:t.timeFieldName,fromDate:o,toDate:r,dslQuery:i,runtimeMappings:t.getRuntimeMappings(),...e})},{abortSignal:null==l?void 0:l.signal}))).rawResponse;return await Object(s.d)({searchHandler:e,dataView:t,field:a,fromDate:o,toDate:r,size:u})}catch(e){throw new Error("Could not provide field stats",{cause:e})}}}}]);