RavenDB:字段未索引异常

时间:2015-08-27 20:40:36

标签: c# linq ravendb

当我尝试使用其中我尝试索引的字段查询文档时,RavenDB会抱怨它实际上并未编入索引。

文件 - “jobs / 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

有没有人对我在哪里出错了?

1 个答案:

答案 0 :(得分:2)

您的索引应如此指定:

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