The problem: I am trying to upgrade from deprecated HRC (7.13) to new REST Client 8.6 in Java.
We use nested queries, but although there is a special NestedQuery.Builder object in the new java client, its not possible to construct the same object as with an old one client.
Old HRC Java code:
BoolQueryBuilder innerQueryBuilder = ...;
QueryBuilders.nestedQuery("Addresses", innerQueryBuilder, ScoreMode.None);
It produces following JSON request:
{
"query": {
"nested": {
"query": {
"bool": {
"must": [
{
"match": {
"Addresses.Town": {
"query": "Frankfurt",
"operator": "AND"
}
}
},
{
"match": {
"Addresses.Street": {
"query": "Theodor",
"operator": "AND"
}
}
}
]
}
},
"path": "Addresses"
}
}
}
But if try to get the same result with the new one client - it makes no "nested" wrapping at all, although it adds necessary top level attribute name using "."
Query q = QueryBuilders.nested()
.path("Addresses")
.query(innerQueryBuilder.build()._toQuery())
.scoreMode(ChildScoreMode.None)
.build()
.query();
The result is incomplete and according current documentation not correct:
{
"query": {
"bool": {
"must": [
{
"match": {
"Addresses.Town": {
"operator": "and",
"query": "Frankfurt"
}
}
},
{
"match": {
"Addresses.Street": {
"operator": "and",
"query": "Theodor"
}
}
}
]
}
}
}
So am I doing something wrong or I miss something? How may I make the query really "nested" as before?