# Usage of setBucketsPaths

**URL:** <https://discuss.elastic.co/t/usage-of-setbucketspaths/38625>\
**Category:** Elasticsearch\
**Created:** [January 7, 2016, 2:09pm UTC](https://discuss.elastic.co/t/usage-of-setbucketspaths/38625 "2016-01-07T14:09:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)\
**Post date:** [January 7, 2016, 2:09pm UTC](https://discuss.elastic.co/t/usage-of-setbucketspaths/38625/1 "2016-01-07T14:09:27Z")

</div>

I'm writing a pipeline aggregation in Java. This is part of my aggregation definition via the REST interface:

```
"active_users": {
  "bucket_script": {
    "buckets_path": {
      "added": "users_added",
      "removed": "users_removed"
    },
    "script": "added - removed"
  }
}
```

In Java I can write:

```
.subAggregation(
  PipelineAggregatorBuilders.bucketScript("active_users")
    .setBucketsPathsMap(new HashMap() {{
      put("added", "users_added");
      put("removed", "users_removed");
    }})
  .script(new Script("added - removed"))
)
```

But can the setBucketsPaths method be used? Something like:

```
.subAggregation(
  PipelineAggregatorBuilders.bucketScript("active_users")
    .setBucketsPaths(
      "added", "users_added",
      "removed", "users_removed"
    )
  .script(new Script("added - removed"))
)
```

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 7, 2016, 4:07pm UTC](https://discuss.elastic.co/t/usage-of-setbucketspaths/38625/2 "2016-01-07T16:07:08Z")

</div>

No, you couldn't write t like that. The setBucketPaths() method on the Bucket\_script agg is for anonymous bucketsPaths, each bucketpath in the array or params list is assigned to a variable in the script named \_value where is the index of the variable in the array. So you could do this instead:

```auto
.subAggregation(
  PipelineAggregatorBuilders.bucketScript("active_users")
    .setBucketsPaths("users_added", "users_removed")
  .script(new Script("_value0 - _value1"))
)

```

Hope that helps

---

<div class="post-metadata">

**Author:** ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)\
**Post date:** [January 8, 2016, 6:36am UTC](https://discuss.elastic.co/t/usage-of-setbucketspaths/38625/3 "2016-01-08T06:36:21Z")

</div>

Exactly what I wanted! 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:** [July 5, 2017, 11:26pm UTC](https://discuss.elastic.co/t/usage-of-setbucketspaths/38625/4 "2017-07-05T23:26:09Z")

</div>


