Extract query result in csv file

Hi all,
can you help me how would i extract the java query output in csv file my code is given below.

try {
            RangeQueryBuilder rangeQ = QueryBuilders
                    .rangeQuery("@timestamp")
                    .gte("1663632000000")
                    .lte("1663804799000")
                    .format("epoch_millis");

            TermsAggregationBuilder termsAggregation = AggregationBuilders
                    .terms("term_by_client_id")
                    .field("labels.client_id")
                    .size(100000)
                    .minDocCount(1);

            termsAggregation
                    .subAggregation(
                            AggregationBuilders
                                    .sum("sum_by")
                                    .field("labels.row_count")
                    );
            termsAggregation
                    .subAggregation(
                            AggregationBuilders
                                    .terms("term_By_job")
                                    .field("labels.job_id")
                    );


            SearchRequest searchRequest = new SearchRequest();
            searchRequest.indices("*itm*");


            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(rangeQ);
            searchSourceBuilder.aggregation(termsAggregation);
           // searchSourceBuilder.size(100000);
            searchRequest.source(searchSourceBuilder);

            SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
            System.out.println(searchResponse);

            Aggregations aggregations = searchResponse.getAggregations();
            Map<String, Aggregation> aggregationMap = aggregations.asMap();
            for (Map.Entry<String, Aggregation> each : aggregationMap.entrySet()){
                System.out.println((each.getValue()));
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

i want to extract the query result in csv file with this program, how i can impliment the export logic in this not able to understand i have tried but it is not woriking for me.
Thanks.

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