我可以将查询调整为仅显示相关区域设置吗?

时间:2019-07-09 13:05:02

标签: azure-cosmosdb azure-cosmosdb-sqlapi

我有一个查询

SELECT c
FROM c 
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Dam'

我试图将其调整为仅显示WHERE子句中指定的相关语言环境,所以我尝试将其调整为:

SELECT c.locales[0]
FROM c 
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Dam'

但是这没有帮助,因为它可能不是locales [0],我曾假设联接将使数组的相关部分始终显示为索引[0],但我错了

如何调整查询以显示整个文档,但仅显示语言环境数组中的相关部分?

请注意,我希望显示整个文档,但只显示该数组中的相关区域设置。

文档如下:

{
    "id": "0570eca0-8f16-4c85-a985-e3a271bcc6bc",
    "_id": "5b07c2bfbc7407000122e8b4",
    "artno": "0614460008",
    "vendor": "Acme",
    "updatedAt": "2019-06-25T18:50:33.167Z",
    "locales": [
        {
            "title": "Gestreiftes T-Shirt",
            "description": "Gestreiftes T-Shirt aus Baumwolljersey.",
            "categories": [
                "Herren",
                "Große Größen",
                "T-Shirts & Tanktops",
                "T-Shirt"
            ],
            "brand": null,
            "images": [
                ],
            "country": "DE",
            "currency": "EUR",
            "language": "de",
            "variants": [
                {
                    "artno": "0614460008005",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XL",
                        "color": "Schwarz/Weiß gestreift"
                    }
                },
                {
                    "artno": "0614460008002",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "S",
                        "color": "Schwarz/Weiß gestreift"
                    }
                },
                {
                    "artno": "0614460008004",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "L",
                        "color": "Schwarz/Weiß gestreift"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XS",
                        "color": "Schwarz/Weiß gestreift"
                    }
                },
                {
                    "artno": "0614460008006",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XXL",
                        "color": "Schwarz/Weiß gestreift"
                    }
                },
                {
                    "artno": "0614460008003",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "M",
                        "color": "Schwarz/Weiß gestreift"
                    }
                }
            ]
        },
        {
            "title": "Striped T-shirt",
            "description": "Striped T-shirt in cotton jersey.",
            "categories": [
                "Men",
                "T-shirts & Vests",
                "Short Sleeve",
                "T-shirt"
            ],
            "brand": null,
            "images": [
                   ],
            "country": "UK",
            "currency": "GBP",
            "language": "en",
            "variants": [
                {
                    "artno": "0614460008006",
                    "urls": [
                        ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XXL",
                        "color": "Black/White striped"
                    }
                },
                {
                    "artno": "0614460008005",
                    "urls": [

                    ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XL",
                        "color": "Black/White striped"
                    }
                },
                {
                    "artno": "0614460008004",
                    "urls": [

                    ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "L",
                        "color": "Black/White striped"
                    }
                },
                {
                    "artno": "0614460008002",
                    "urls": [

                    ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "S",
                        "color": "Black/White striped"
                    }
                },
                {
                    "artno": "0614460008003",
                    "urls": [

                    ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "M",
                        "color": "Black/White striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 8.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XS",
                        "color": "Black/White striped"
                    }
                }
            ]
        },
        {
            "title": "Randig t-shirt",
            "description": "En randig t-shirt i bomullstrikå.",
            "categories": [
                "Herr",
                "T-shirts & Linnen",
                "Kortärmat",
                "T-shirt"
            ],
            "brand": null,
            "images": [
                 ],
            "country": "SE",
            "currency": "SEK",
            "language": "sv",
            "variants": [
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "XS",
                        "color": "Svart/Vitrandig"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "XL",
                        "color": "Svart/Vitrandig"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "S",
                        "color": "Svart/Vitrandig"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "XXL",
                        "color": "Svart/Vitrandig"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "M",
                        "color": "Svart/Vitrandig"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 99,
                    "stock": 1,
                    "attributes": {
                        "size": "L",
                        "color": "Svart/Vitrandig"
                    }
                }
            ]
        },
        {
            "title": "Striped T-shirt",
            "description": "Striped T-shirt in cotton jersey.",
            "categories": [
                "Men",
                "T-shirts & Tank tops",
                "Short Sleeves",
                "T-shirt"
            ],
            "brand": null,
            "images": [
                  ],
            "country": "US",
            "currency": "USD",
            "language": "en",
            "variants": [
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 0,
                    "attributes": {
                        "size": "S",
                        "color": "Black/white striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 0,
                    "attributes": {
                        "size": "XL",
                        "color": "Black/white striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 0,
                    "attributes": {
                        "size": "M",
                        "color": "Black/white striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 0,
                    "attributes": {
                        "size": "L",
                        "color": "Black/white striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 0,
                    "attributes": {
                        "size": "XXL",
                        "color": "Black/white striped"
                    }
                },
                {
                    "artno": "0614460008001",
                    "urls": [

                    ],
                    "price": 9.99,
                    "stock": 1,
                    "attributes": {
                        "size": "XS",
                        "color": "Black/white striped"
                    }
                }
            ]
        }
    ],
    "relatedArtno": [
        "0614460001",
        "0614460002",
        "0614460005",
        "0614460006",
        "0614460007",
        "0614460011",
        "0614460012"
    ],
    "_rid": "QEwcAMCVWqgGAAAAAAAAAA==",
    "_self": "dbs/QEwcAA==/colls/QEwcAMCVWqg=/docs/QEwcAMCVWqgGAAAAAAAAAA==/",
    "_etag": "\"2e00f1ca-0000-0c00-0000-5d144d660000\"",
    "_attachments": "attachments/",
    "_ts": 1561611622
}

1 个答案:

答案 0 :(得分:1)

马特。根据您的描述,我认为您可以进行如下更改:

SELECT locales
FROM c 
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Herr'

输出:

enter image description here


更新sql:

SELECT c.id,c.artno,c.XXX(what properties you want),.....
,locales
FROM c 
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Herr'