Cosmos DB json 匹配所有单词的数组

Cosmos DB json array that matchs all the words

我需要一个可以从单词列表中获取文档的查询,例如,如果我使用


    select c from c join (SELECT distinct VALUE c.id FROM c JOIN word IN c.words WHERE  word in('word1',word2) and tag in('motorcycle')) ORDER BY c._ts desc

它会带来两个文档,我只想检索第一个,因为它匹配两个词而不是一个。

文档 1

 "c": {
            "id": "d0f1723c-0a55-454a-9cf8-3884f2d8d61a",
            "words": [
                "word1",
                "word2",
                "word3",
             ]}

文件 2

 "c": {
            "id": "d0f1723c-0a55-454a-9cf8-3884f2d8d61a",
            "words": [
                "word1",
                "word4",
                "word5",
             ]}

您应该能够在 WHERE 子句中使用两个 ARRAY_CONTAINS 表达式来解决这个问题(不需要 JOIN):

SELECT c.id FROM c
WHERE ARRAY_CONTAINS(c.words, 'word1')
AND ARRAY_CONTAINS(c.words, 'word2')

这应该 return 您的第一个文档的 ID。