# Terms Aggregation request returning empty Bucket list in Java TransportClient

**URL:** <https://discuss.elastic.co/t/terms-aggregation-request-returning-empty-bucket-list-in-java-transportclient/131963>\
**Category:** Elasticsearch\
**Created:** [May 15, 2018, 2:48pm UTC](https://discuss.elastic.co/t/terms-aggregation-request-returning-empty-bucket-list-in-java-transportclient/131963 "2018-05-15T14:48:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![najib](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@najib](https://discuss.elastic.co/u/najib)\
**Post date:** [May 15, 2018, 2:48pm UTC](https://discuss.elastic.co/t/terms-aggregation-request-returning-empty-bucket-list-in-java-transportclient/131963/1 "2018-05-15T14:48:36Z")

</div>

Hey there, I am using ES 6.2.4 with the Java TransportClient to perform a search request (through an inline Script). The search request has a Terms aggregation by field. When I run the search request in Kibana, I properly get the aggregated counts that I want. However in Java, the getBuckets object returns an emtpy list. This is the Search script:

```
{
  "_source": ["_id", "text"],
          "from" : 0, "size" : 50,
          
    "query": {
        "function_score": {
          
          "query": {
            "multi_match": {
              "type": "most_fields", 
              "query": "{{param_text}}",
              "fields": ["title", "text^2"]
            }
          },
          "boost": 1,
          
          "script_score" : {
                "script" : {
                  "source": "_score * doc['boost'].value"
                }
            }
          
        }
    },
    
    "aggs" : {
        "document_types" : {
            "terms" : { "field" : "document_type" }
        }
    }
}

```

This is the Java code:

```
SearchResponse response = new SearchTemplateRequestBuilder(transportClient).setScript(s).setScriptType(ScriptType.INLINE).setScriptParams(params)
				.setRequest(new SearchRequest()).get().getResponse();

		List<Aggregation> aggregations = response.getAggregations().asList();
	Terms agg = response.getAggregations().get("document_types");
		for (Bucket entry : agg.getBuckets()) {
			String key = entry.getKeyAsString(); // bucket key
			long docCount = entry.getDocCount(); // Doc count
		}

```

Although the agg object is properly returned, the agg.getBuckets() method returns an empty list.

Your help would be much appreciated.  
Kind regards,  
Najib

---

<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:** [June 12, 2018, 2:48pm UTC](https://discuss.elastic.co/t/terms-aggregation-request-returning-empty-bucket-list-in-java-transportclient/131963/2 "2018-06-12T14:48:38Z")

</div>

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