Error with Term Frequency Script combined with Aggregation script

I have two scripts in my query, one that gets a term frequency and one that calculates an aggregate. If I run this query with just one of the scripts present, it runs find. However , if both are present, then I get an error that looks like this:

+org.elasticsearch.index.search.nested.NonNestedDocsFilter@b2a8151b)],from[0],size[0]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchParseException[failed to parse / load source]; nested: IndexOutOfBoundsException[docID must be >= 0 and < maxDoc=39 (got docID=7623)]; ]; "

Here's my query:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "has_parent": {
                "type": "article",
                "filter": {
                  "bool": {
                    "must": [
                      {
                        "term": {
                          "profile_id": 12
                        }
                      },
                      {
                        "script": {
                          "script": "_index['title'][term].tf() >= frequency",
                          "params": {
                            "term": "foobar",
                            "frequency": 1
                          }
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "revenue": {
      "sum": {
        "script": "Map map = new HashMap(); for(field in ['total_goals','total_events']){if(_source.containsKey(field)){for(e in _source[field]){ map.put(field+e.name, e.value.intValue());}}};  doc['revenue'].value "
      }
    }
  },
  "size": 0
}

Anyone have any idea what's going on? Why should these scripts affect each other?