Hi I need help in dynamic sort of "asc" and "desc" based upon 3 fields which I need to select one by one from select option front. Currently I'm sorting on the basis of any particular field hardcoded given field.
Problem: When I try to sort using lookup transform field it will not sort.
Complete code :
{
"autosize": {"type": "fit", "contains": "padding"},
"width": "container",
"height": "container",
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"name": "telemetry",
"url": {
"%context%": true,
"%timefield%": "datetime",
"index": "telemetry-*",
"body": {
"_source": ["type"],
"aggs": {
"time_bins": {
"date_histogram": {
"field": "datetime",
"interval": "1w",
"min_doc_count": 1
},
"aggs": {
"customer": {
"terms": {"field": "customer.keyword"},
"aggs": {"type_agg": {"terms": {"field": "type.keyword"}}}
}
}
}
}
}
},
"format": {
"property": "aggregations.time_bins.buckets",
"type": "json",
"parse": {"customer": "customer.buckets"}
}
},
"transform": [
{"flatten": ["customer.buckets"], "as": ["buckets"]},
{"calculate": "substring(datum.key_as_string, 0, 10)", "as": "x"},
{
"calculate": "toDate(datum.key_as_string) + 7*24*60*60*1000",
"as": "to_date"
},
{
"calculate": "utcFormat(datum.to_date, '%Y-%m-%dT%H:%M:%S.000Z')",
"as": "iso_date"
},
{"calculate": "datum.buckets.key", "as": "customer_name"},
{
"lookup": "customer_name",
"from": {
"data": {
"name": "customers-epo",
"url": {
"index": "customers-epo*",
"body": {
"_source": ["renewal_date", "revenue_ttm", "TELEMETRY_NAME"],
"query": {
"constant_score": {
"filter": {
"bool": {
"must": {"exists": {"field": "revenue_ttm.keyword"}},
"must_not": {"term": {"revenue_ttm.keyword": ""}}
}
}
}
}
}
},
"format": {
"property": "hits.hits",
"type": "json",
"parse": {
"_source.renewal_date": "utc:\"%Y-%m-%dT%H:%M:%SZ\"",
"_source.revenue_ttm": "number",
"_source.TELEMETRY_NAME": "TELEMETRY_NAME"
}
}
},
"key": "_source.TELEMETRY_NAME",
"fields": [
"_source.renewal_date",
"_source.revenue_ttm",
"_source.TELEMETRY_NAME"
]
}
}
],
"params": [
{
"name": "sortOrder",
"value": "ascending",
"bind": {"input": "radio", "options": ["ascending", "descending"]}
},
{
"name": "seletedFields",
"value": "customer_name",
"select": {"type": "click"},
"bind": {
"input": "select",
"options": [
"_source.renewal_date",
"_source.revenue_ttm",
"customer_name"
]
}
}
],
"encoding": {
"x": {
"field": "x",
"axis": {
"orient": "top",
"fontSize": "container",
"title": "Weekly",
"labelColor": "black",
"labelOverlap": true
}
},
"y": {
"field": "customer_name",
"axis": {
"title": "Customers",
"labelOverlap": true,
"fontSize": "container",
"grid": true,
"gridColor": "grey",
"gridDash": [3, 1],
"gridOpacity": 0.1,
"labelColor": "black",
"labelpadding": 40
},
"sort": {
"field": "customer_name",
"order": {
"signal": "sortOrder === 'ascending' ? 'ascending' : 'descending'"
}
}
},
"size": {
"field": "buckets.doc_count",
"type": "quantitative",
"title": "Events",
"scale": {"domain": [0, 10, 100], "range": [10, 40, 100]}
},
"color": {"value": "rgba(0,0,255,0.2)"},
"tooltip": [
{"field": "x", "title": "Date"},
{"field": "buckets.doc_count", "type": "quantitative", "title": "Events"},
{"field": "_source.renewal_date", "title": "renewal_date"},
{"field": "_source.revenue_ttm", "title": "revenue_ttm"},
{"field": "customer_name", "title": "customer_name"}
]
},
"layer": [
{"mark": {"type": "circle", "filled": true}},
{
"transform": [
{"flatten": ["buckets.type_agg.buckets"], "as": ["type_bucket"]},
{"filter": {"field": "type_bucket.key", "equal": "CREATE_PROPOSAL"}},
{
"calculate": "'https://search-epa-elk-ivz33xdiltaqdvhbbm27e2lnpm.us-east-1.es.amazonaws.com/_dashboards/app/discover#/?_g=(filters:!(),query:(language:kuery,query:%27%27),refreshInterval:(pause:!t,value:0),time:(from:%27' + datum.key_as_string + '%27,to:%27' + datum.iso_date + '%27))&_a=(columns:!(_source),filters:!((%27$state%27:(store:appState),meta:(alias:!n,disabled:!f,index:e698da20-922e-11eb-9886-7d16d17d0228,key:customer,negate:!f,params:(query:%27' + datum.buckets.key + '%27),type:phrase),query:(match_phrase:(customer:%27' + datum.buckets.key + '%27))),(%27$state%27:(store:appState),meta:(alias:!n,disabled:!f,index:e698da20-922e-11eb-9886-7d16d17d0228,key:customer,negate:!t,params:!(QA,system,dev),type:phrases,value:%27QA,%20system,%20dev%27),query:(bool:(minimum_should_match:1,should:!((match_phrase:(customer:QA)),(match_phrase:(customer:system)),(match_phrase:(customer:dev))))))),index:e698da20-922e-11eb-9886-7d16d17d0228,interval:auto,query:(language:kuery,query:%27type%20:%20%22CREATE_PROPOSAL%22%27),sort:!(!(datetime,asc)))'",
"as": "link"
}
],
"selection": {
"select_point": {
"type": "single",
"fields": ["type_bucket"],
"on": "click",
"empty": "none"
}
},
"encoding": {
"x": {
"field": "x",
"axis": {
"title": "Weekly",
"labelColor": "black",
"labelOverlap": true,
"orient": "top"
}
},
"y": {
"field": "buckets.key",
"axis": {
"title": "Customers",
"labelOverlap": true,
"fontSize": "container",
"grid": true,
"gridColor": "grey",
"gridDash": [3, 1],
"gridOpacity": 0.1,
"labelColor": "black",
"labelpadding": 40
}
},
"size": {
"field": "type_bucket.doc_count",
"type": "quantitative",
"scale": {"domain": [0, 10, 100], "range": [10, 30, 1000]},
"condition": {
"test": "datum.type_bucket.key === 'CREATE_PROPOSAL'",
"value": {"expr": "datum.type_bucket.doc_count+70"}
}
},
"color": {"value": "red"},
"tooltip": [
{"field": "x", "title": "Date"},
{
"field": "buckets.doc_count",
"type": "quantitative",
"title": "Events"
},
{
"field": "type_bucket.doc_count",
"type": "quantitative",
"title": "Proposals"
},
{"field": "_source.renewal_date", "title": "renewal_date"},
{"field": "_source.revenue_ttm", "title": "revenue_ttm"},
{"field": "customer_name", "title": "customer_name"}
],
"href": {"field": "link"}
},
"mark": {"type": "circle", "filled": true}
}
]
}
First index (telemetry) data Look like:
{
"aggregations" : {
"time_bins" : {
"buckets" : [
{
"key_as_string" : "2020-01-01T00:00:00.000Z",
"key" : 1577836800000,
"doc_count" : 45241,
"customer" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 4699,
"buckets" : [
{
"key" : "Nsssichosssls",
"doc_count" : 26721,
"type_agg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "xx",
"doc_count" : 25703
},
{
"key" : "xx",
"doc_count" : 576
},
{
"key" : "xxx",
"doc_count" : 185
},
{
"key" : "xx",
"doc_count" : 120
},
{
"key" : "xx",
"doc_count" : 41
},
{
"key" : "xx",
"doc_count" : 30
},
{
"key" : "xx",
"doc_count" : 30
},
{
"key" : "xx",
"doc_count" : 28
},
{
"key" : "xx",
"doc_count" : 7
},
{
"key" : "xx",
"doc_count" : 1
}
]
}
},
{
"key" : "Firstsssss ffss",
"doc_count" : 2838,
"type_agg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "cc",
"doc_count" : 2274
},
{
"key" : "dd",
"doc_count" : 180
},
{
"key" : "xx",
"doc_count" : 146
},
{
"key" : "xx",
"doc_count" : 108
},
{
"key" : "xx",
"doc_count" : 42
},
{
"key" : "xx",
"doc_count" : 34
},
{
"key" : "xx",
"doc_count" : 31
},
{
"key" : "xx",
"doc_count" : 23
}
]
}
}
]
}
}
]
}
}
}
Second Index data look like :
{
"hits" : {
"total" : {
"value" : 10,
"relation" : "eq"
},
"hits" : [
{
"_index" : "customers-epo",
"_type" : "_doc",
"_id" : "dsfs",
"_score" : 1.0,
"_source" : {
"TELEMETRY_NAME" : "xssddfdfrfr",
"renewal_date" : "2018-07-01",
"revenue_ttm" : 69076.9
}
},
{
"_index" : "customers-epo",
"_type" : "_doc",
"_id" : "sdsffr",
"_score" : 1.0,
"_source" : {
"TELEMETRY_NAME" : "sssss ffffff",
"renewal_date" : "2018-11-30",
"revenue_ttm" : 26589.7
}
}
]
}
}
How it's look like image:
Main Section of code
"field": "customer_name",
"order": {
"signal": "sortOrder === 'ascending' ? 'ascending' : 'descending'"
}
}```
Currently I need to change this field to ```[
"_source.renewal_date",
"_source.revenue_ttm",
"_source.TELEMETRY_NAME"
]```
any of this field to sort.
Thanks