2015-08-27 71 views
1

當我嘗試查詢使用中它一個領域,我試圖指數則RavenDB抱怨說,它實際上並不是索引的文檔。RavenDB:現場沒有索引異常

的文件 - 「工作/ 332」 - 如下:

{ 
    "Type": "Outbound", 
    "Flight": { 
     "Operator": "SAS", 
     "Number": "267", 
     "Origin": "MAN", 
     "Gate": "019", 
     "Stand": "A12", 
     "STD": "2015-08-20T09:15:00.0000000Z", 
     "ETD": "2015-08-20T09:16:00.0000000Z", 
     "Status": "On Time", 
     "Seat": "16F" 
    }, 
    "PAX": { 
     "Name": "Mr. John Smith", 
     "Types": [ 
      { 
       "Description": "WCHC" 
      }, 
      { 
       "Description": "DPNA" 
      } 
     ], 
     "Prenotified": true 
    }, 
    "Stages": [ 
     { 
      "AssignedAgents": [ 
       { 
        "Id": 34, 
        "Name": "Derek Brown" 
       } 
      ], 
      "StageStart": { 
       "Location": "T1 Checkin", 
       "Time": "2015-08-20T08:00:00.0000000Z" 
      }, 
      "StageEnd": { 
       "Location": "Lounge 1", 
       "Time": "2015-08-20T08:25:00.0000000Z" 
      } 
     }, 
     { 
      "AssignedAgents": null, 
      "StageStart": { 
       "Location": "Lounge 1", 
       "Time": "2015-08-20T08:45:00.0000000Z" 
      }, 
      "StageEnd": { 
       "Location": "Gate 019", 
       "Time": "2015-08-20T08:55:00.0000000Z" 
      } 
     } 
    ] 
} 

我創建了以下靜態指標:

public class Job_Agent : AbstractIndexCreationTask<Job> 
{ 
    public Job_Agent() 
    { 
     Map = jobs => from job in jobs 
         from stage in job.Stages 
         from agent in stage.AssignedAgents 
         select new 
         { 
          agent.Id 
         }; 
    } 
} 

當我嘗試用下面的查詢來查詢文件:

_session.Query<Job, Job_Agent>() 
        .First(u => u.Stages 
         .Any(t => t.AssignedAgents 
          .Any(a => a.Id == 34))); 

然後我得到以下信息:

The field 'Stages_AssignedAgents_Id' is not indexed, cannot query on fields that are not indexed 

有沒有人對我已經錯在這兒,有什麼想法?

回答

2

您指數應像這樣被指定:

from job in docs.Jobs 
select new 
{ 
    Stages_AssignedAgents_Id = job.Stages.SelectMany(x=>x.AssignedAgents).Select(x=>x.Id) 
} 
+1

就是這樣。謝謝,奧倫。 –