ElasticSearch - 父子关系

时间:2014-05-07 23:25:17

标签: elasticsearch nest

我正在尝试使用NEST客户端为C#创建父子关系。这是我的代码。我正在使用elasticsearch 1.1.1,这段代码似乎是将testp1对象添加到testparent索引,但它没有向testchild索引添加任何对象。如果我没有使用索引参数传递父项,它似乎工作正常。对此有任何帮助表示赞赏。

private static void LoadTestData()
{
    var esClient = CreateNESTConnection();
    esClient.MapFluent<testparent>(x => x
        .IndexName("testdb")
        .TypeName("testparent")
        .IdField(y => y.SetPath("Id"))
        .Properties(cprops => cprops
            .String(a => a.Name("id"))
            .Number(a => a.Name("parentid").Type(NumberType.@long))
            .Number(a => a.Name("prop1").Type(NumberType.@long))
            .Number(a => a.Name("prop2").Type(NumberType.@long))
            .Boolean(a => a.Name("checkflag"))
    ));

    esClient.MapFluent<testchild>(x => x
        .IndexName("testdb")
        .TypeName("testchild")
        .SetParent("testparent")
        .Properties(cprops => cprops
            .Number(a => a.Name("dockey").Type(NumberType.@long))
            .Number(a => a.Name("docvalue").Type(NumberType.@float))
    ));

    testparent testp1 = new testparent();
    testp1.checkflag = true;
    testp1.id = "7";
    testp1.parentid = 77;
    testp1.prop1 = 1;
    testp1.prop2 = 2;
    testchild testc1 = new testchild();
    testc1.dockey = 100;
    testc1.docvalue = 111;

    testchild testc2 = new testchild();
    testc2.dockey = 100;
    testc2.docvalue = 111;

    esClient.Index(testp1, "testdb");
    IndexParameters parameters = new IndexParameters();
    parameters.Parent = "7";
    var t = esClient.Index(testc1, "testdb", parameters);
    Console.WriteLine(t.OK);
    t = esClient.Index(testc2, "testdb", parameters);
    Console.WriteLine(t.OK);
}

0 个答案:

没有答案
相关问题