1

I have a SearchSourceBuilder which has all blocks like Query,From, Size, Aggregations etc. But later I want to remove only the Aggregations blocks for some use case fully before sending the DSL to ES.

Example, I need to remove the entire aggregations block from the SearchSourceBuilder from the entire DSL enter image description here

Abhishek Sengupta
  • 2,938
  • 1
  • 28
  • 35

1 Answers1

1

SearchSourceBuilder class has multiple aggregation methods to build different types of aggregations as shown in the intelliJ image below

You just need to remove those aggregation method from SearchSourceBuilder

For example, my below code uses query filters, size and agss

SearchSourceBuilder queryBuilder = new SearchSourceBuilder()
                .query(queryFilters)
                .size(0)
                .aggregation(nodeTasksAggs);

And if I don't want aggs, I can just use below code

SearchSourceBuilder queryBuilder = new SearchSourceBuilder()
                .query(queryFilters)
                .size(0);

enter image description here

Amit
  • 30,756
  • 6
  • 57
  • 88
  • HI @Amit thanks for the reply. but here my requirement is bit different, for sone use case I cannot modify the original Java object/DSL. SO at the very end I just need to remove the agg block from the SSB. I cannot stop aggs getting added to it . But at the last I just want to stop aggs block to go to ES for querying. – Abhishek Sengupta Oct 26 '22 at 05:40
  • @AbhishekSengupta, you have to do it conditionally in your code, there is no other way.. since you are building the queries in Java and you if know in what cases you want the `agss` block its easy to do it programatically in java code – Amit Oct 26 '22 at 05:43
  • yeah looks like thats the only way to do it... thanks – Abhishek Sengupta Oct 26 '22 at 05:45
  • 1
    @AbhishekSengupta its been sometime, please upvote and accept the answer if it was useful :) Thanks in advance – Amit Nov 04 '22 at 07:22