如何在Azure Cosmos DB中深度搜索JSON? [英] How to search JSON in depth in Azure Cosmos DB?

查看:82
本文介绍了如何在Azure Cosmos DB中深度搜索JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Cosmos DB中存储了如下所示的JSON文件.我想搜索活动/消息中的文本.

I have JSON files like below stored in Cosmos DB. I want to search text in activities/message.

{
  "id": "575858a7-f814-41fd-ae5a-6f38ba2da957",
  "name": "Test Name",
  "activities": [
    {
      "message": "activity 1.1 message",
      "messageType": "type1"
    },
    {
      "message": "activity 1.2 message",
      "messageType": "type2"
    }
  ]
}

我发现我可以使用如下所示的搜索方式.

I find out that I can use search like below.

SELECT * FROM c
WHERE CONTAINS(c.activities[0].message, "activity")

但是,这只能搜索活动数组中的第一条记录.如何搜索数组中的所有记录?谢谢.

But, this can only search the first record in the array of activities. How to search all records in the array? Thanks.

推荐答案

您需要在查询中应用联接,因此,数组将被视为规范化实体,然后可以应用过滤器.

You need to apply a join on your query, so then you array will be treated as a normalized entity and then you can apply the filter.

select c.id, a.message
from c join a in c.activities
where CONTAINS(a.message,"activity")

更多信息

这篇关于如何在Azure Cosmos DB中深度搜索JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆