Vega script

Hello,

I am currently using Custom visualization using vega and would like to put a filter on the field option.

{
  $schema: https://vega.github.io/schema/vega-lite/v4.json
  title: vega test
  data: {
    url: {
      index: content*
      body: {
        size: 0
        query: {
          bool: {
            must: [
            ]
            filter: [
              {
                match_all: {
                }
              }
            ]
            should: [
            ]
            must_not: [
            ]
          }
        }
        aggs: {
          projectCode: {
            terms: {
              field: project_code.raw
              size: "20"
              order: {
                total_cost: desc
              }
            }
            aggs: {
              total_cost: {
                sum: {
                  field: cost
                }
              }
            }
          }
        }
      }
    }
    format: {
      property: aggregations.projectCode.buckets
    }
  }
  mark: {
    type: bar
  }
  encoding: {
    x: {
      field: total_cost.value
      axis: {
        title: cost
      }
      type: quantitative
    }
    y: {
      field: key
      axis: {
        title: project
      }
      type: nominal
      sort: desc
    }
    tooltip: [
      {
        field: key
        title: project
      }
      {
        field: total_cost.value
        title: cost
      }
    ]
  }
}

By using this json, I can get top 20 project code, but I would like to get a list that only matches the script I wrote below. I am not sure where I can put this script because it gives eserror if I put inside aggregations.

{
  "lang" : "painless",
  "source" : "doc['project_code.raw'].value.substring(10,14) == "CONT""
}

Where did you put it in the aggregation? it seems it is not a vega problem but Elasticsearch problem.
You may have to debug the aggregation query itself using Dev Tools in Kibana or something.