问题
Environment: NodeJS client, Marklogic 8 server.
The query from NodeJS is:
var query = qb.where(
qb.directory('/root/dir/'),
qb.scope(
qb.property('sources'),
qb.value('brand','MyBrand')
)
);
The translated query is:
{
"whereClause": {
"query": {
"queries": [
{
"directory-query": {
"uri": [
"/root/dir/"
]
}
},
{
"container-query": {
"json-property": "sources",
"value-query": {
"json-property": "brand",
"text": [
"MyBrand"
]
}
}
}
]
}
},
"queryType": "structured",
"queryFormat": "json"
}
The query returns 10501 documents.
But 20 documents do not match query condition (sources.brand = MyBrand)
Sample extract for an incorrect document "/root/dir/0029aaa0-53dc-11e6-8f88-311cf9885168.json" returned:
{
sources:
[
{
"somefield1": {
"somesubfield": "0D793B77-826A-4E19-BCEF-5F1E5C07271A"
},
"somefield2": "6408467",
"brand": "NA",
"somefield3": "TEST"
},
{
"somefield": {
"somesubfield": "832B4AE2-C817-4960-BF8C-63374E7D1B66"
},
"somefield2": "6408467",
"brand": "NA",
"somefield3": "TEST"
}
],
otherFieldsSkipped: true,
badScope:
[
{
"brand": "MyBrand",
},
],
}
The problem occurs on 2 different platforms.
Only a few documents are incorrect where badScope[0].brand match the value (MyBrand).
Thanks
回答1:
This behavior might be a bug. It would be good to file a support request to dig deeper.
It is possible to get false positives when you submit an unfiltered query and the parent property with the correct name contains a child property with the correct name but an incorrect value while a different property elsewhere in the document has the same name as the child property and the specified value.
You can eliminate those false positives either by submitting a filtered query (which are slower) or by turning on the element value position index.
By default, the Node.js API executes unfiltered queries.
To see whether that explains the false positives you are seeing, you can turn on filtering:
... the query ...
.withOptions({search:'filtered'})
For more information about this query builder method, see:
http://docs.marklogic.com/jsdoc/queryBuilder.html#withOptions
来源:https://stackoverflow.com/questions/40125093/marklogic-data-do-not-comply-with-query