-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[Lens] Support histogram mapping type for all numeric functions #90357
Merged
wylieconlon
merged 12 commits into
elastic:master
from
wylieconlon:lens/histogram-types
Feb 16, 2021
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b35234f
[Lens] Support histogram mapping type
wylieconlon a5b8914
Merge remote-tracking branch 'origin/master' into lens/histogram-types
wylieconlon 10ae985
Fix field stats and allow max/min
wylieconlon 6f804fd
Fix types
wylieconlon 1de16cf
Merge branch 'master' into lens/histogram-types
kibanamachine 8ef1191
Revert to regular sample data
wylieconlon 699caba
Merge branch 'master' into lens/histogram-types
kibanamachine 3354939
Simplify server code
wylieconlon 83428af
Merge remote-tracking branch 'fork/lens/histogram-types' into lens/hi…
wylieconlon c40eedf
Merge remote-tracking branch 'origin/master' into lens/histogram-types
wylieconlon cfad77d
Add test for edge case
wylieconlon 3a4c305
Merge branch 'master' into lens/histogram-types
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+120 KB
(110%)
src/plugins/home/server/services/sample_data/data_sets/logs/logs.json.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ const columnSortOrder = { | |
ip: 3, | ||
boolean: 4, | ||
number: 5, | ||
histogram: 6, | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,11 @@ export async function initFieldsRoute(setup: CoreSetup<PluginStartContract>) { | |
return result; | ||
}; | ||
|
||
if (field.type === 'number') { | ||
if (field.type === 'histogram') { | ||
return res.ok({ | ||
body: await getNumberOnlyHistogram(search, field), | ||
}); | ||
} else if (field.type === 'number') { | ||
return res.ok({ | ||
body: await getNumberHistogram(search, field), | ||
}); | ||
|
@@ -205,6 +209,81 @@ export async function getNumberHistogram( | |
}; | ||
} | ||
|
||
export async function getNumberOnlyHistogram( | ||
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. nit: It looks like this code is almost the same as |
||
aggSearchWithBody: (body: unknown) => Promise<unknown>, | ||
field: IFieldType | ||
): Promise<FieldStatsResponse> { | ||
const fieldRef = getFieldRef(field); | ||
|
||
const searchBody = { | ||
sample: { | ||
sampler: { shard_size: SHARD_SIZE }, | ||
aggs: { | ||
min_value: { | ||
min: { field: field.name }, | ||
}, | ||
max_value: { | ||
max: { field: field.name }, | ||
}, | ||
sample_count: { value_count: { ...fieldRef } }, | ||
}, | ||
}, | ||
}; | ||
|
||
const minMaxResult = (await aggSearchWithBody(searchBody)) as ESSearchResponse< | ||
unknown, | ||
{ body: { aggs: typeof searchBody } } | ||
>; | ||
|
||
const minValue = minMaxResult.aggregations!.sample.min_value.value; | ||
const maxValue = minMaxResult.aggregations!.sample.max_value.value; | ||
|
||
let histogramInterval = (maxValue! - minValue!) / 10; | ||
|
||
if (Number.isInteger(minValue!) && Number.isInteger(maxValue!)) { | ||
histogramInterval = Math.ceil(histogramInterval); | ||
} | ||
|
||
if (histogramInterval === 0) { | ||
return { | ||
totalDocuments: minMaxResult.hits.total.value, | ||
sampledValues: minMaxResult.aggregations!.sample.sample_count.value!, | ||
sampledDocuments: minMaxResult.aggregations!.sample.doc_count, | ||
histogram: { buckets: [] }, | ||
}; | ||
} | ||
|
||
const histogramBody = { | ||
sample: { | ||
sampler: { shard_size: SHARD_SIZE }, | ||
aggs: { | ||
histo: { | ||
histogram: { | ||
field: field.name, | ||
interval: histogramInterval, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const histogramResult = (await aggSearchWithBody(histogramBody)) as ESSearchResponse< | ||
unknown, | ||
{ body: { aggs: typeof histogramBody } } | ||
>; | ||
|
||
return { | ||
totalDocuments: minMaxResult.hits.total.value, | ||
sampledDocuments: minMaxResult.aggregations!.sample.doc_count, | ||
sampledValues: minMaxResult.aggregations!.sample.sample_count.value!, | ||
histogram: { | ||
buckets: histogramResult.aggregations!.sample.histo.buckets.map((bucket) => ({ | ||
count: bucket.doc_count, | ||
key: bucket.key, | ||
})), | ||
}, | ||
}; | ||
} | ||
|
||
export async function getStringSamples( | ||
aggSearchWithBody: (body: unknown) => unknown, | ||
field: IFieldType | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For reviewers: You can test the histogram data in the sample logs, but I think this is probably not a good idea to merge. So I'll plan to remove these changes before merging.