Phạm Quốc Bảo
Phạm Quốc Bảo

Reputation: 894

Cloudant Search index

I have a table with data as below:

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


    }
]

and the Search index function

enter image description here the returned results are:

enter image description here

Please give me your thought how to split data and display with the key name on each value in results. eg:

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

Upvotes: 0

Views: 132

Answers (1)

Mayya Sharipova
Mayya Sharipova

Reputation: 405

If your make your index like:

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});
      }
    }
  }
}

than your fields will be:

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

Is this the result you intended to get?

Upvotes: 2

Related Questions