No result back when doing nested aggregation using java api

I bumped into a situation that when I send a query through http rest, I get result, but when equivalent aggregation send from java api, I can get result back.

I use Elasticsearch v1.7.2

here is my query send to http REST

{
    "from" : 0,
    "size" : 0,
    "query" : {
        "filtered" : {
            "query" : {
                "match_all" : {}
            },
            "filter" : {
                "match_all" : {}
            }
        }
    },
    "aggregations" : {
        "byCategory" : {
            "nested" : {
                "path" : "categoryStatus"
            },
            "aggregations" : {
                "sumByProductCount" : {
                    "sum" : {
                        "field" : "categoryStatus.productCount"
                    }
                }
            }
        }
    }
}

here is equivalent aggregation use java api

AbstractAggregationBuilder agg =
        AggregationBuilders.nested("byCategory").path("categoryStatus").subAggregation(
                        sum("sumByProductCount").field("categoryStatus.productCount")
                );

Any idea?

No. your aggregation builder looks good.

So what is the potential problem? Java API library?
I stuck on this many days and I don't want to shift code to use WebRequest directly to http REST to get result.
I can't upgrade ES to new version currently, have to stay on 1.7.2.

I can't tell you. I don't have access to your code and you did not share it with us.

Above code is how I construct query that using java API (official elastic java client) and send it to ES.

What information I missed to provide, please help guide me. many thanks.
I do see there are many "doc mapped as nested object" will cause problem during aggregation, but seems in my case, rest api send me correct result.

How do you use this agg object would be a good start?
How you know the Java response is incorrect?

Share anything which can help to reproduce your problem.

A simple Java Test class would be super useful (create index, put the mapping, index a doc, then search).

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