The index you are proposing is correct (/ path / to [@attribute]), but unfortunately the xDB optimizer does not currently recognize this particular case, since the "target node" stored in the index is always an element, not an attribute . If the / path / to / @ attribute has few results, you can optimize this by slightly changing your request for this: distinct-values (/ path / to [@attribute] / @ attribute). Using this query, the optimizer recognizes that there is an index that it can use to access the to element, but then it still has access to the target document to retrieve the attribute for the @attribute step. That is why this will only benefit when there are several hits: each hit is likely to gain access to another data page.
What you can also do is access the keys in the index directly through the API: XhiveIndexIf.getKeys (). It will be very fast, but it is clear that it is not very convenient (and should be done by the optimizer).
Obviously, the optimizer can handle this. I will add it to the error tracker.
source share