Basic and proper start with NEST library


#1

Hello,

We are planning to use ElasticSearch NEST for our current project. Tried to prepare a small sample but stuck. Need help.

Here is my query.. we have very complex data structure .. many tables are not linked through any mapping but store related information .. also sharing parent tables (storing common identity fields) .. but for an start I tried one to many relationship .. I am facing issue when trying to create parent child mapping .. the error is "Can't specify parent if no parent field has been configured"

public class Degree
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DegreeId { get; set; }
public string DegreeName { get; set; }
}

public class Employee
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int EmployeeId { get; set; }
    public int DepartmentId { get; set; }
    public string EmployeeName { get; set; }
    public int Age { get; set; }
    public DateTime DateOfBirth { get; set; }

   [Nest.Nested(Store = false, IncludeInParent = true)]
   public List<ESEmployeeDegree> EmployeeDegrees { get; set; }
}

public class EmployeeDegree
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EmployeeDegreeId { get; set; }
public int EmployeeId { get; set; }
public int DegreeId { get; set; }
}

here is my code:
public void CreateEmployee(Employee employee, UserAccount account)
{
var employeeResponse = client.Index(employee, i => i.Index(indexName).Type("employee").Id(employee.EmployeeId));

        foreach (var employeeDegree in employee.EmployeeDegree)
        {
            var degreeResponse = client.Index(employeeDegree, i => i.Index(indexName).Type("employeedegrees").Parent(employee.EmployeeId.ToString()).Id(employeeDegree.EmployeeDegreeId)); //here I am getting error 
        }
    }

Searched a lot but not able to find a proper way to start ... how to set Employee as a parent for EmployeeDegree .. please help and guide .. if possible please share working example.


#2

Please guide ..


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.