2016-11-21 119 views
0

我有一個數據表如下:Cloudant搜索索引

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


    } 
] 

和搜索索引功能

enter image description here 返回的結果是:

enter image description here

請給我您的想法是如何分割數據並在結果中的每個值上顯示鍵名。例如:

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

回答

2

如果你讓你的指數,如:

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

這是你爲了得到結果?

+0

感謝您的回覆,我們可以將:rate,description,code和provider_type添加到名爲item_service [i]的組中。 –

+0

是的,您可以 - 但它會成爲您在問題中發佈的原始代碼。在搜索響應中返回的「fields」沒有層次結構,您不能爲其添加子字段(例如「rate」,「description」...)。 –

+0

非常感謝你mayya :) –