2016-11-21 122 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 :) –