Java Api percolate with aggregations

Hi,
I am running percolate action and it's works greate but.. when I am trying to add aggregation to percolate request but its returns with no matches.
like:

PercolateResponse response = client.preparePercolate()
.setIndices("myIndexName")
.setDocumentType("myDocumentType")
.setSource(docBuilder).addAggregation(AggregationBuilders.terms("ruleNames").field("ruleName")).execute().actionGet();

My percolator mapping is:

  PUT news-feed-index/.percolator/_mapping
{
        ".percolator" : {
                "properties" : {
                        "query" : {
                                "type" : "object",
                                "enabled" : false
                        },
                        "usersRuleState" : { 
                            "type": "nested",
                            "properties": {
                                "user": {"type": "string"},
                                "isActive": {"type": "boolean"}
                            }
                        },
                        "filter": {"type": "string"},
                        "owner": {"type": "string"},
                        "ruleName": {"type": "string"}
                                                         
                        }
                }
        }

and I am trying to do this but in Java Api:

POST /news-feed-index/news/_percolate/
{
  "doc": {
 "subject": "Murder in Mexico",
 "body": "",
 "priority":1
  },
  "size": 0, 
"aggs" : { 
    "users" : { 
        "terms" : { 
          "field" : "user"
        }
    }
}
}

Any help?

Can you try to use PercolateSourceBuilder the build request body and then set that directly on the request? the addAggregation(...) and other builder methods undo what has been set via setSource(...) method.

Something like this:

PercolateSourceBuilder sourceBuilder = new PercolateSourceBuilder()
                .setDoc(docBuilder)
                .addAggregation(AggregationBuilders.terms("ruleNames").field("ruleName"));
        setSource(sourceBuilder);
client.preparePercolate()
   .setIndices("myIndexName")
   .setDocumentType("myDocumentType")
   .setSource(sourceBuilder)

Thanks!

I solved it other way.
After I read https://github.com/elastic/elasticsearch/issues/11162 I understand that the problem is in setSource().

   PercolateResponse response = client.preparePercolate()
.setIndices("myIndexName")
.setDocumentType("myDocumentType")
.setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc(doc) )
.addAggregation(AggregationBuilders.terms("ruleNames").field("ruleName")).execute().actionGet();

This is solved it.
:innocent: