Get JAVA API by id with routing



Is it possible to use the JAVA API to perform a get on a type that has required routing and you don't have the attribute from which the routing is performed ?

For example, you have type A, which is parent of B, which has required routing.

You can use the JAVA API as:

GetRequestBuilder searchBuilder = esClient.prepareGet(index, "B", "objectB_ID");

But, as routing is required, you'd get an exception. So you could add the routing (prior to the execution) as:


But, while "objectA_ID" is actually an attribute of my B object, you don't now it's value until you do retrieve the document. I'm aware that you could set a "path" attribute to the routing (prior to 1.5 ES, I believe), but it is not set in this case.

So, you must have the routing value to get the document, but you'll only know the routing value, when you have the document. Kind of a dead-loop..

Is there a turnaround ? I've tried to use a "path" routing, but without much success:



(system) #2