As best I can recreate your test with 6.0-2.3, this works for me.
When debugging database queries, one useful technique is to move things in memory. If it still doesn't work, this throws suspicion on the database query. When I try that using 6.0-2.3, the results seem to be correct.
declare namespace log="some/namespace/definition" ;
document {
<log:record id="00000001" date="2013-04-14T01:42:02.922+01:00" type="change" xmlns:log="some/namespace/definition">
<log:head>
<some-header-info/>
</log:head>
<log:changes>
<log:change field="dateModified">
<log:old-value>2012-11-06T00:00:00.0000000</log:old-value>
<log:new-value>2013-03-20T00:00:00.0000000</log:new-value>
</log:change>
<log:change field="moduleCodes">
<log:old-value>
<log:moduleCodes>
<log:moduleCodes-value code="AAA"/>
</log:moduleCodes>
</log:old-value>
<log:new-value>
<log:moduleCodes>
<log:moduleCodes-value code="AAA"/>
<log:moduleCodes-value code="BBB"/>
</log:moduleCodes>
</log:new-value>
</log:change>
</log:changes>
</log:record> }
/log:record[log:changes/log:change/@field = "moduleCodes"]/xdmp:path(.)
=>
/log:record
declare namespace log="some/namespace/definition" ;
document {
<log:record id="00000001" date="2013-04-14T01:42:02.922+01:00" type="change" xmlns:log="some/namespace/definition">
<log:head>
<some-header-info/>
</log:head>
<log:changes>
<log:change field="dateModified">
<log:old-value>2012-11-06T00:00:00.0000000</log:old-value>
<log:new-value>2013-03-20T00:00:00.0000000</log:new-value>
</log:change>
<log:change field="moduleCodes">
<log:old-value>
<log:moduleCodes>
<log:moduleCodes-value code="AAA"/>
</log:moduleCodes>
</log:old-value>
<log:new-value>
<log:moduleCodes>
<log:moduleCodes-value code="AAA"/>
<log:moduleCodes-value code="BBB"/>
</log:moduleCodes>
</log:new-value>
</log:change>
</log:changes>
</log:record> }
/log:record/log:changes/log:change[@field = "moduleCodes"]/xdmp:path(.)
=>
/log:record/log:changes/log:change[2]
So the implication is that the problem is in the index or the way the index is queried. You can try to debug that using xdmp:query-trace(true())
at the start of your query. For example:
declare namespace log="some/namespace/definition" ;
xdmp:query-trace(true()),
/log:record[log:changes/log:change/@field = "moduleCodes"]/xdmp:describe(.),
/log:record/log:changes/log:change[@field = "moduleCodes"]/xdmp:describe(.)
With 6.0-2.3 these both return the expected results for me.
fn:doc("test")/log:record
fn:doc("test")/log:record/log:changes/log:change[2]
Here are the traces, from the ErrorLog.txt file:
Analyzing path: fn:collection()/log:record[log:changes/log:change/@field = "moduleCodes"]/xdmp:describe(.)
Step 1 is searchable: fn:collection()
Step 2 is searchable: log:record[log:changes/log:change/@field = "moduleCodes"]
Step 3 is unsearchable: xdmp:describe(.)
First 2 steps of path are searchable: fn:collection()/log:record[log:changes/log:change/@field = "moduleCodes"]
Gathering constraints.
Comparison contributed hash value constraint: log:change/@field = "moduleCodes"
Step 2 predicate 1 contributed 3 constraints: log:changes/log:change/@field = "moduleCodes"
Comparison contributed hash value constraint: log:change/@field = "moduleCodes"
Step 2 predicate 1 contributed 1 constraint: log:changes/log:change/@field = "moduleCodes"
Step 2 contributed 4 constraints: log:record[log:changes/log:change/@field = "moduleCodes"]
Executing search.
Selected 1 fragment to filter
xdmp:eval("declare namespace log="some/namespace/definition" ;...", (), <options xmlns="xdmp:eval"><database>598453498912235799</database><root>/tmp</root><isolati...</options>)
Analyzing path: fn:collection()/log:record/log:changes/log:change[@field = "moduleCodes"]/xdmp:describe(.)
Step 1 is searchable: fn:collection()
Step 2 is searchable: log:record
Step 3 is searchable: log:changes
Step 4 is searchable: log:change[@field = "moduleCodes"]
Step 5 is unsearchable: xdmp:describe(.)
First 4 steps of path are searchable: fn:collection()/log:record/log:changes/log:change[@field = "moduleCodes"]
Gathering constraints.
Step 2 contributed 1 constraint: log:record
Comparison contributed hash value constraint: log:change/@field = "moduleCodes"
Step 4 predicate 1 contributed 1 constraint: @field = "moduleCodes"
Step 4 contributed 1 constraint: log:change[@field = "moduleCodes"]
Comparison contributed hash value constraint: log:change/@field = "moduleCodes"
Step 4 predicate 1 contributed 1 constraint: @field = "moduleCodes"
Comparison contributed hash value constraint: log:change/@field = "moduleCodes"
Step 4 predicate 1 contributed 1 constraint: @field = "moduleCodes"
Step 4 contributed 1 constraint: log:change[@field = "moduleCodes"]
Step 3 contributed 1 constraint: log:changes
Executing search.
Selected 1 fragment to filter