# Bucket aggregation with java api version 8.11

**URL:** https://discuss.elastic.co/t/bucket-aggregation-with-java-api-version-8-11/349729
**Category:** Elasticsearch
**Tags:** painless
**Created:** [December 20, 2023, 1:54pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-java-api-version-8-11/349729 "2023-12-20T13:54:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Darth\_vader\_22](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darth_vader_22/32/130197_2.png) [@Darth\_vader\_22](https://discuss.elastic.co/u/Darth_vader_22)
#### Post date: [December 20, 2023, 1:54pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-java-api-version-8-11/349729/1 "2023-12-20T13:54:51Z")

</div>

Hi everyone ! can anyone please help me convert below query in java i'm struggling with the aggregation part i have been stuck to this for days now , any help would be appreciated

```auto
{
	"query": {},
	"aggregations": {
		"authentication_attempts_by_day_and_structure_id": {
			"filters": {
				"filters": {
					"authentication_attempts": {
						"terms": {
							"custom_request": ["path1", "path2", "path3"],
							"boost": 1.0
						}
					},
					"failed_authentication_attempts": {
						"bool": {
							"filter": [{
									"terms": {
										"custom_request": ["path4", "path5", "path6"],
										"boost": 1.0
									}
								}, {
									"terms": {
										"httpcode": ["404", "500"],
										"boost": 1.0
									}
								}
							],
							"adjust_pure_negative": true,
							"boost": 1.0
						}
					}
				},
				"other_bucket": false,
				"other_bucket_key": "_other_"
			},
			"aggregations": {
				"byStructureId": {
					"terms": {
						"field": "structureid",
						"size": 200,
						"min_doc_count": 1,
						"shard_min_doc_count": 0,
						"show_term_doc_count_error": false,
						"order": {
							"_key": "asc"
						}
					},
					"aggregations": {
						"byDay": {
							"terms": {
								"script": {
									"source": "doc['@timestamp'].value.withZoneSameInstant(ZoneId.of('Europe/Paris')).toLocalDate()",
									"lang": "painless"
								},
								"size": 31,
								"min_doc_count": 1,
								"shard_min_doc_count": 0,
								"show_term_doc_count_error": false,
								"order": {
									"_key": "asc"
								}
							}
						}
					}
				}
			}
		}
	}
}

```

---

<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 17, 2024, 1:55pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-java-api-version-8-11/349729/2 "2024-01-17T13:55:41Z")

</div>

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