# Invalid path element for multibucket key

**URL:** <https://discuss.elastic.co/t/invalid-path-element-for-multibucket-key/212303>\
**Category:** Elasticsearch\
**Created:** [December 18, 2019, 10:36am UTC](https://discuss.elastic.co/t/invalid-path-element-for-multibucket-key/212303 "2019-12-18T10:36:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomask1](https://avatars.discourse-cdn.com/v4/letter/t/8edcca/32.png) [@thomask1](https://discuss.elastic.co/u/thomask1)\
**Post date:** [December 18, 2019, 10:36am UTC](https://discuss.elastic.co/t/invalid-path-element-for-multibucket-key/212303/1 "2019-12-18T10:36:39Z")

</div>

Hi!

So we are trying the following:

```auto
POST /items/_search
{
  "size": 0,
  "aggs": {
    "some-agg": {
      "date_histogram": {
        "field": "created_at",
        "interval": "day",
        "min_doc_count": 0
      },
      "aggs": {
        "items": {
          "filters": {
            "filters": {
              "foo": {
                "term": {
                  "document_type": "foo"
                }
              },
              "bar": {
                "term": {
                  "document_type": "bar"
                }
              }
            }
          }
        },
        "bars_to_foos_rate": {
          "bucket_script": {
            "buckets_path": {
              "foos": "items['foo']._count",
              "bars": "items['bar']._count"
            },
            "script": "params.foos / params.bars"
          }
        }
      }
    }
  }
}

```

This is giving us the following error:  
`Invalid path element [items['bar']._count] in path [items['bar']._count]`

Looking at [the 1st and 4th code blocks here](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-aggregations-pipeline.html#buckets-path-syntax) make us think we are using the correct bucket path syntax

Especially since doing:

```auto
POST /items/_search
{
  "size": 0,
  "aggs": {
    "some-agg": {
      "date_histogram": {
        "field": "created_at",
        "interval": "day",
        "min_doc_count": 0
      },
      "aggs": {
        "items": {
          "filters": {
            "filters": {
              "foo": {
                "term": {
                  "document_type": "foo"
                }
              },
              "bar": {
                "term": {
                  "document_type": "bar"
                }
              }
            }
          }
        }
      }
    }
  }
}

```

Yields:

```auto
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 14,
    "successful" : 14,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "some-agg" : {
      "buckets" : [
        {
          "key_as_string" : "2019-05-29T00:00:00.000Z",
          "key" : 1559088000000,
          "doc_count" : 7,
          "items" : {
            "buckets" : {
              "bar" : {
                "doc_count" : 0
              },
              "foo" : {
                "doc_count" : 0
              }
            }
          }
        }
      ]
    }
  }
}

```

We're using Elasticsearch 7.1 on AWS

Any clues what we might be doing wrong?

Many thanks!

---

<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:** [January 15, 2020, 10:45am UTC](https://discuss.elastic.co/t/invalid-path-element-for-multibucket-key/212303/2 "2020-01-15T10:45:14Z")

</div>

Closed on January 15, 2020, 10:45am UTC

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