【问题标题】:RavenDB: Field Not Indexed ExceptionRavenDB:字段未索引异常
【发布时间】:2015-08-28 17:49:03
【问题描述】:

当我尝试使用其中的一个字段查询文档时,我尝试对其进行索引,然后 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

有人对我在这里出错的地方有任何想法吗?

【问题讨论】:

    标签: c# linq ravendb


    【解决方案1】:

    你的索引应该这样指定:

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

    【讨论】:

    • 就是这样。谢谢,奥伦。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    相关资源
    最近更新 更多