Skip to content
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

[Mappings editor] Add support for histogram field type #76671

Conversation

alisonelizabeth
Copy link
Contributor

@alisonelizabeth alisonelizabeth commented Sep 3, 2020

Fixes #63937

I also created a common component for the meta parameter. While working on this PR, I found out from the ES team that this parameter is available to most field types so I added support where appropriate via df56ddc.

Release note

The mappings editor in the Index Templates UI now supports configuring the histogram field type. Support for the meta parameter was also added to the boolean, binary, completion, date, flattened, geo_point, numeric, range, search_as_you_type, token_count and text field types.

Screen Shot 2020-09-03 at 12 26 36 PM

@alisonelizabeth alisonelizabeth added release_note:enhancement v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more Feature:Mappings Editor Index mappings editor UI v7.10.0 labels Sep 3, 2020
@alisonelizabeth alisonelizabeth marked this pull request as ready for review September 3, 2020 19:51
@alisonelizabeth alisonelizabeth requested a review from a team as a code owner September 3, 2020 19:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@sebelga
Copy link
Contributor

sebelga commented Sep 7, 2020

@elasticmachine merge upstream

sebelga
sebelga previously approved these changes Sep 7, 2020
Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @alisonelizabeth ! I left a few comments to tidy things up but no blockers. Cheers.

} from '../../field_parameters';
import { BasicParametersSection, AdvancedParametersSection } from '../edit_field';
import { FormDataProvider } from '../../../../shared_imports';

const getDefaultToggleValue = (param: 'locale' | 'format' | 'boost', field: FieldType) => {
const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
if (param === 'meta') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for meta is '' so L27 should be enough

import { AdvancedParametersSection } from '../edit_field';

export const BinaryType = () => {
const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we default to the more generic

return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;

like we do in the "range_type"?

@@ -24,8 +25,9 @@ const getDefaultToggleValue = (param: string, field: FieldType) => {
case 'boost': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
case 'meta':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "null_value" could have been left, and simply add "meta" on top of "boost"

import { EditFieldFormRow, AdvancedParametersSection } from '../edit_field';

const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'max_input_length': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
case 'meta': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply add "meta" on top of "max_input_length"

case 'null_value': {
return field.null_value !== undefined && field.null_value !== '';
return field[param] !== undefined && field[param] !== '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: I think "null_value" could have been left, and simply add "meta" on top of "boost"

case 'null_value': {
return field.null_value !== undefined && field.null_value !== '';
return field[param] !== undefined && field[param] !== '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here :) on top of "ignore_malformed"

@@ -29,6 +30,9 @@ const getDefaultToggleValue = (param: string, field: FieldType) => {
case 'max_shingle_size': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
case 'meta': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here: on top of "max_shingle_size"

@@ -46,8 +47,9 @@ const getDefaultToggleValue = (param: string, field: FieldType) => {
case 'analyzers': {
return field.search_analyzer !== undefined && field.search_analyzer !== field.analyzer;
}
case 'meta':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: on top of "boost"

case 'null_value': {
return field.null_value !== undefined && field.null_value !== '';
return field[param] !== undefined && field[param] !== '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here :)

return JSON.stringify(value, null, 2);
},
serializer: (value: string) => {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no more the need of try/catch in serializer as now it is guaranteed to be a valid value (it has passed the validations defined, so here isJsonField).

So it could simply by

serializer: (value: string) => {
  const parsed = JSON.parse(value);
  // If an empty object was passed, strip out this value entirely.
  if (!Object.keys(parsed).length) {
    return undefined;
  }
  return parsed;
},

@sebelga
Copy link
Contributor

sebelga commented Sep 7, 2020

Ups! I went a bit fast on clicking the "Approve button" 😊
There is a strange bug I discovered.

  1. Create a template with an histogram field and a meta like this
{ "meta": true }
  1. Save ---> everything ok
  2. Edit the template and the field and set the meta as
["meta"] // valid JSON but not valid for ES
  1. Save ---> error
[illegal_argument_exception] composable template [my-template] template after composition is invalid
  1. Edit the template and put back the initial meta (object) value

  2. Save ---> still error?

  3. Edit the field... and disable the meta (toggle OFF)

  4. Save ---> ok

  5. Edit the template + edit the field and add valid meta (object)

  6. Save ---> still error??? (this is very strange, we can't save a meta anymore on that field)

@sebelga
Copy link
Contributor

sebelga commented Sep 7, 2020

[EDIT]

So I played a bit more with it and the steps to reproduce are slightly different:

  1. Create an index with JUST a name + and the logs* index pattern
  2. Save the template (this is the request about to be saved)

Screenshot 2020-09-07 at 11 21 42

  1. Edit the template and add 1 histogram field. Edit the field to add a meta.

Even without looking at the advanced configuration form (navigate to that tab), we get all of them in the request

Screenshot 2020-09-07 at 11 24 19

And saving it not allowed.

[illegal_argument_exception] composable template [my-template] template after composition is invalid
  1. I then remove the meta (toggle OFF). The request sill has all the advanced settings but I am allowed to save

Screenshot 2020-09-07 at 11 25 21

In your other PR with constant_keyword, no advanced config is added to the mappings but the same error is returned when adding some meta (with logs* as index pattern)

Screenshot 2020-09-07 at 12 04 35

Screenshot 2020-09-07 at 12 05 03

@sebelga sebelga dismissed their stale review September 7, 2020 10:16

I'd like to investigate a bit further before approving as there is a very odd behavior. Maybe it is 100% on ES side, but I'd like to confirm this.

@alisonelizabeth
Copy link
Contributor Author

alisonelizabeth commented Sep 14, 2020

Thanks for the review @sebelga! I believe I addressed your comments. Would you mind taking another look?

Also, as mentioned in #76564, I believe the error you were hitting when saving meta was due to setting a boolean value instead of a string.

I was not able to reproduce the issue you saw related to the advanced settings config. Can you retest and let me know if you're still able to reproduce?

@alisonelizabeth
Copy link
Contributor Author

@elasticmachine merge upstream

@sebelga sebelga self-requested a review September 17, 2020 10:41
Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes! Tested locally and works as expected. You didn't add the validation for the meta values (string) but I guess it will get merged with the other PR.

[Edit] I could not reproduce the issue I mentioned with the advanced settings, which is good 👍

@sebelga
Copy link
Contributor

sebelga commented Sep 17, 2020

@elasticmachine merge upstream

@alisonelizabeth
Copy link
Contributor Author

Thanks for the second review @sebelga!

Thanks for making the changes! Tested locally and works as expected. You didn't add the validation for the meta values (string) but I guess it will get merged with the other PR.

The validation is there now that #76564 has been merged. I also updated the constant_keyword field type to use the common meta component.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
indexManagement 506 +2 504

async chunks size

id value diff baseline
indexManagement 1.6MB +3.7KB 1.6MB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Mappings Editor Index mappings editor UI release_note:enhancement Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mappings editor] Add UI form for histogram datatype
4 participants