2016-11-21 16 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]という名前の1つのグループに追加できますか? –

+0

はい、できますが、質問に投稿した元のコードになります。検索応答の 'fields'戻り値に階層構造がない場合、それらにサブフィールドを追加することはできません(例:" rate "、" description "...)。 –

+0

ありがとうmayya :) –

関連する問題