Cloudant 搜索索引

Cloudant Search index

我有一个 table 数据如下:

[
    {
        "payment_id": 1,
        "provider_id": "ABC123  ",
        "status": "pending",
        "item_service": [
                        {
                "code": "NY100",
                "provider_type":"Medical_Center",
                "description": "Initial Consultation - History, examination and treatment",
                "rate": "20"
            },
            {
                "code": "NY101",
                "provider_type":"Medical_Center",
                "description": "Brief Consultation - Selective review, examination and treatment",
                "rate": "25"
            },
            {
                "code": "NY102",
                "provider_type":"Medical_Center",
                "description": "Standard Consultation - History, examination and treatment",
                "rate": "30"
            }
        ]


    }
]

和搜索索引功能

返回结果为:

请给我你的想法如何拆分数据并在结果中的每个值上显示键名。例如:

  "code": "PY102",
  "provider_type":"Medical_Center",
   "description": "Standard Consultation - History, examination and treatment",
   "rate": "30"

如果您将索引设置为:

function (doc) {
  if (doc.item_service){
    for (var m in doc.item_service){
      for (var n in doc.item_service[m]){
        index(n, doc.item_service[m][n], {"store":true});
      }
    }
  }
}

你的字段将是:

"fields": {
        "rate": [
          "30",
          "25",
          "20"
        ],
        "description": [
          "Standard Consultation - History, examination and treatment",
          "Brief Consultation - Selective review, examination and treatment",
          "Initial Consultation - History, examination and treatment"
        ],
        "code": [
          "NY102",
          "NY101",
          "NY100"
        ],
        "provider_type": [
          "Medical_Center",
          "Medical_Center",
          "Medical_Center"
        ]
      }

这是您想要得到的结果吗?