我有一个带有134k文档的集合的Cosmos DB,每个文档包含2个字符串属性(名为ChemicalName和EchNo)和3个字符串集合(名为CasNos,IndexNos和ReachNos)。
Document JSON:
{
"id": "9cb924ad-a100-4fce-9dc9-30ec968de585",
"ChemicalName": "MyChemical",
"EchaNumber": 1,
"EcNo": "111-222-3",
"CasNos": [
"4444-55-6"
],
"IndexNos": [
"777-888-99-0"
],
"ReachNos": [
"01-0123456789-38-0000",
"01-0123456789-38-0001",
"01-0123456789-38-0002",
"01-0123456789-38-0003",
"01-0123456789-38-0004",
"01-0123456789-38-0006",
"01-0123456789-38-0007",
"01-0123456789-38-0008",
"01-0123456789-38-XXXX"
],
"IndexScrapeDate": "2018-01-19T12:30:20.0404174Z",
"ChemicalScrapeDate": null,
"_rid": "96VvAOgIVwABAAAAAAAAAA==",
"_self": "dbs/96VvAA==/colls/96VvAOgIVwA=/docs/96VvAOgIVwABAAAAAAAAAA==/",
"_etag": "\"00007e4d-0000-0000-0000-5a69b49b0000\"",
"_attachments": "attachments/",
"_ts": 1516876955
}
集合具有索引定义:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/EchaNumber/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/ChemicalName/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/CasNos/[]/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/EcNo/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/IndexNos/[]/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/ReachNos/[]/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
}
],
"excludedPaths": []
}
我在Dotnet Core 2.0中实现了代码,并且正在使用SQL API。
当我搜索集合时,我使用以下SQL来查找我需要的文档的ID:
SELECT VALUE c.id FROM IndexCollection c JOIN cas IN c.CasNos JOIN indx IN c.IndexNos WHERE CONTAINS(c.ChemicalName,"searchVal") OR STARTSWITH(cas,"searchVal") OR STARTSWITH(c.EcNo,"searchVal") OR STARTSWITH(indx,"searchVal")
我通过在CasNos字符串集合属性中搜索已知的部分匹配来验证它。
然后我还需要添加对ReachNos的搜索并将其添加到搜索中:
SELECT VALUE c.id FROM IndexCollection c JOIN cas IN c.CasNos JOIN indx IN c.IndexNos JOIN rch IN c.ReachNos WHERE CONTAINS(c.ChemicalName,"searchVal") OR STARTSWITH(cas,"searchVal") OR STARTSWITH(c.EcNo,"searchVal") OR STARTSWITH(indx,"searchVal") OR STARTSWITH(rch,"searchVal")
...但是一旦我添加ReachNos进行搜索,它就会停止查找任何结果,因为我使用与上面相同的搜索。 如果我修改SQL只搜索ReachNos属性,它将从给定的结果中找到结果。我从该属性输入一个已知值。
任何人都可以。告诉我为什么这不起作用? 我尝试了第一个SQL的所有组合,无论我搜索了什么属性,它都工作正常,直到我添加了ReachNos属性。
编辑:我应该添加我已在本地Cosmos DB Emulator和azure上测试过。 EDIT2:添加了文档JSON/感谢名单