我只需要在第一个索引中查询doctor 的所有信息.

Here is my sample XML dataHere is my sample JSON data: XML和JSON数据都是相同的.我刚刚将XML转换为JSON格式. 我还有更多这样的文件.

I tried this query in this image个 这个查询显示了所有信息,但我只需要第一个doctor 的信息. 我还try 了命令提示符

以下是我的样例JSON代码块:但我还有更多类似的文档

{
    "doctors": {
        "doctor":[
            {
                "ssn": "257-79-xxxx",
                "name": "Mavis Bxx",
                "address": "xxxx Rusk Drive",
                "country": "France",
                "email": "",
                "phone": "",
                "patients": {
                    "patient": [
                        {
                            "gender": "Male",
                            "name": "Itch xxxx",
                            "address": "xx Cottonwood Avenue",
                            "revenue": "254",
                            "_country": "Spain",
                            "_id": "27"
                        },
                        {
                            "gender": "Male",
                            "name": "Damon xxxxx",
                            "address": "xx David Trail",
                            "revenue": "370",
                            "_country": "Germany",
                            "_id": "21"
                        }
                    ]
                },
                "_id": "6"
            },
            {
                "ssn": "179-45-xxxx",
                "name": "Tobie Conxxxx",
                "address": "x Comanche Center",
                "country": "Spain",
                "email": "tconringh@xxx.xxx",
                "phone": "+86 998 262 xxxx",
                "patients": {
                    "patient": {
                        "gender": "Male",
                        "name": "Vergil Tome",
                        "address": "x Melody Drive",
                        "revenue": "254",
                        "_country": "Germany",
                        "_id": "15"
                    }
                },
                "_id": "18"
            },
            {
                "ssn": "777-59-xxxx",
                "name": "Gertrud Macxxxx",
                "address": "x Buell Drive",
                "country": "USA",
                "email": "gmaclaig2@xxx.com",
                "phone": "+62 975 394 xxxx",
                "patients": {
                    "patient": [
                        {
                            "gender": "Non-binary",
                            "name": "Dre Skxxxx",
                            "address": "x Becker Circle",
                            "revenue": "400",
                            "_country": "Germany",
                            "_id": "20"
                        },
                        {
                            "gender": "Female",
                            "name": "Arleyne Lestxxxx",
                            "address": "xx Farragut Court",
                            "revenue": "225",
                            "_country": "France",
                            "_id": "22"
                        }
                    ]
                },
                "_id": "3"
            }

推荐答案

您需要更改收集数据格式.您当前的格式是单个 Big Data .不是一种可争辩的格式.

所以

从当前格式

{
    "doctors": {
        "docker": [
            {
                ...
                "patients": {
                    "patient": [
                        {
                            ...
                        },
                        {
                            ...
                        }
                    ]
                },
            },
            {
                ...
            }
        ]
    }
}

转换为此格式

[
    {
        ...
        "patients": [
            {
                ...
            },
            {
                ...
            }
        ]
    },
    {
        ...
    }
]

测试JSON

[
    {
        "ssn": "2xx-7x-4xxx",
        "name": "Mavis Bxxxed",
        "address": "9xxx Rusk Drive",
        "country": "France",
        "email": "",
        "phone": "",
        "patients": [
            {
                "gender": "Male",
                "name": "Itch Txxx",
                "address": "5xx Cottonwood Avenue",
                "revenue": "25x",
                "_country": "Spain",
                "_id": "27"
            },
            {
                "gender": "Male",
                "name": "Damon Wxxx",
                "address": "09xx Dxxxx Trail",
                "revenue": "370",
                "_country": "Germany",
                "_id": "21"
            }
        ],
        "_id": "6"
    },
    {
        "ssn": "19-45-xxxx",
        "name": "Tobie Coxxxx",
        "address": "8x Comxxxx Center",
        "country": "Spain",
        "email": "tconxxxxx@usa.gov",
        "phone": "",
        "patients": [
            {
                "gender": "Male",
                "name": "所以me one",
                "address": "1 Mexxxx Drive",
                "revenue": "254",
                "_country": "Germany",
                "_id": "15"
            }
        ],
        "_id": "18"
    }
]

In Compass View after add data upper data enter image description here

按姓名查找doctor 查询

{ name: "Mavis Bxxxed" }

enter image description here

按患者姓名查找doctor

{ "patients.name": "所以me one" }

enter image description here

如果使用此查询进行相同的搜索

{ "patients.name": "Itch Txxx" }
OR
{ "patients.name": "Damon Wxxx" }

找到第一个 docker 也会有同样的结果吗(梅维斯·巴克斯) 因为它的病人从[开始,到]结束.它是数组类型,是单一大小的数据.

您可以按项目选项进行筛选

  {
    patients: {
      $filter:
      {
          input: "$patients",
          cond: { $eq: [ "$$patient.name", "Itch Txxx"] },
          as: "patient"
      }
    }
  }

enter image description here

或仅显示地址

{ "patients.address" : 1 }

enter image description here

Json相关问答推荐

Golang JSON Date Tim.Date()测试请求

Pandas 对REST API的自定义响应

如何将一个对象添加到多个对象中 JOLT

转换为Json时忽略内部对象中的数组

在 NX 工作区中跨多个应用共享 ngx-translate 翻译文件

从 Inno Setup 中的 JSON 文件的每个对象中读取特定字符串

每次在 SoapUI 中发送请求时,将 JSON 响应的子 node 分配给项目变量

无法使用 vue.js 访问 JSON 数组的项目

无法在 json --data 中使用变量

通过 xslt 将内部 json 转换为 xml 时遇到问题

使用 jq 和 awk 拆分大型 JSON 文件

如何迭代、动态加载我的表单输入元素,然后在 React 中的表单提交上检索输入值?

如何在 Postman 中匹配 json 响应中的内容?并可视化

在 Perl Mojolicious 中呈现 JSON 时防止转义字符

将带有数据和文件的 JSON 发布到 Web Api - jQuery / MVC

将错误消息作为 JSON 对象发送

如何向从文件中检索的 JSON 数据添加键值?

我可以使用空字符串作为对象标识符吗?

未调用 npm package.json 脚本

如何从 BindingResult 获取控制器中的错误文本