Complete the code to create a Lens visualization with drag-and-drop fields.
POST /_lens/visualize
{
"title": "Sales by Category",
"type": "[1]",
"state": {
"datasourceStates": {},
"visualization": {}
}
}The type field defines the visualization type. Here, bar is correct for a bar chart.
Complete the code to specify the field to drag into the Lens visualization.
"state": { "datasourceStates": { "indexpattern": { "layers": { "layer1": { "columns": { "col1": { "operationType": "sum", "sourceField": "[1]" } } } } } } }
The sourceField should be a numeric field to sum, like price.
Fix the error in the Lens state by completing the missing field for bucket grouping.
"columns": { "col1": { "operationType": "terms", "sourceField": "[1]" } }
For bucket grouping by terms, use a keyword field like category.keyword.
Fill both blanks to set the correct operation and field for a date histogram in Lens.
"columns": { "col1": { "operationType": "[1]", "sourceField": "[2]" } }
Date histograms require operationType as date_histogram and a date field like timestamp.
Fill all three blanks to create a Lens visualization with a sum metric and bucket by category.
{
"title": "Sales by Category",
"type": "bar",
"state": {
"datasourceStates": {
"indexpattern": {
"layers": {
"layer1": {
"columns": {
"col1": {
"operationType": "[1]",
"sourceField": "[2]"
},
"col2": {
"operationType": "[3]",
"sourceField": "category.keyword"
}
}
}
}
}
},
"visualization": {}
}
}This Lens visualization sums the price field and buckets by category.keyword using terms aggregation.