【问题标题】:Cloudant Search indexCloudant 搜索索引
【发布时间】:2016-11-21 10:18:32
【问题描述】:

我有一个表格,数据如下:

[
    {
        "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"

【问题讨论】:

    标签: ibm-cloud cloudant


    【解决方案1】:

    如果你的索引是这样的:

    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"
            ]
          }
    

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

    【讨论】:

    • 感谢您的回复,我们可以将:rate、description、code 和 provider_type 添加到名为 item_service[i] 的一组中?
    • 是的,您可以 - 但这将是您在问题中发布的原始代码。 fields 在搜索响应中返回没有层次结构,您不能向它们添加子字段(例如“rate”、“description”...)。
    猜你喜欢
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    相关资源
    最近更新 更多