# Kibana dashboard DSL aggregations problem

**URL:** <https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014>\
**Category:** Kibana\
**Created:** [July 7, 2021, 4:40am UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014 "2021-07-07T04:40:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harryb](https://avatars.discourse-cdn.com/v4/letter/h/6bbea6/32.png) [@harryb](https://discuss.elastic.co/u/harryb)\
**Post date:** [July 7, 2021, 4:40am UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014/1 "2021-07-07T04:40:55Z")

</div>

I am trying to filter an Elastic index to only return one record per doc\_id and which I want to base the visualization on. If I use this in a Kibana dashboard visualization filter I get an error: '[size] query malformed, no start\_object after query name'.

The filter is:

```auto
{
  "size": 500,
  "aggs": {
    "Unique_docs": {
      "terms": {
        "field": "DOC_ID"
      }
    }
  }
}

```

If I remove the size, the error changes to 'unknown field [aggs]'. The DSL runs in the console but not as a dashboard filter. Can anyone tell me if you can use aggregations in a dashboard filter please?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 7, 2021, 7:27am UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014/2 "2021-07-07T07:27:05Z")

</div>

You can't use aggregations in a filter - filter only operate on a per-document basis.

Can you explain which kind of visualization you want to build? Maybe there's another way to achieve your goal.

---

<div class="post-metadata">

**Author:** ![harryb](https://avatars.discourse-cdn.com/v4/letter/h/6bbea6/32.png) [@harryb](https://discuss.elastic.co/u/harryb)\
**Post date:** [July 7, 2021, 10:33pm UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014/3 "2021-07-07T22:33:39Z")

</div>

Thanks Joe - the data has multiple documents with the same doc\_id but I want to sum the values for another field in the record called citationCount but summing it only once for each doc\_id, and showing it in a bar graph as total citations by year. The citationCount values are the same across documents with the same doc\_id.

So I was trying to filter down the index records to get just one per doc\_id, then sum the citationCount by year. Is there another way to do that?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 8, 2021, 7:35am UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014/4 "2021-07-08T07:35:35Z")

</div>

Not directly in the chart configuration, but it should be possible with transforms. Look at [Transform examples | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-examples.html#example-last-log) , this seems very close to your case.

A transform is basically a job you let run in the background which will pre-aggregate your data in some way (e.g. only keeping the latest document).

Then you can do a regular visualization on top of this pre-aggregated index

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 5, 2021, 7:36am UTC](https://discuss.elastic.co/t/kibana-dashboard-dsl-aggregations-problem/278014/5 "2021-08-05T07:36:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
