2016-09-27 1 views
0

다음과 같이 말하면 POCO이 있습니다.중첩 된 객체의 elasticsearch 버전 2.0.0.0 부분 업데이트에 대한 네스트

public class Graph 
{ 
    public string Id { get; set; } // Indexed by this 
    public List<Node> NodeList { get; set; } 
} 

public class Node 
{ 
    public string Id { get; set; } 
    public string Name { get; set; } 
    public List<Edge> EdgeList { get; set; } 
} 

public class Edge 
{ 
    public string Id { get; set; } 
    public double Cost { get; set; } 
} 

부분적으로 업데이트 내 Graph 나는 그것이 Id의에 의해 NodeList에서 기존 Node을 발견하고 NameEdge 등록 정보의 갱신 할 . I Node 개체를 내 NodeList에 새로 추가하고 싶습니다. 기존 업데이트 만 업데이트하려고합니다.

SOFAR 나는 시도했다 :

public void UpdateGraph(string index, Graph graph) 
{ 
    var docPath = new DocumentPath<Graph>(graph.Id).Index(index); 
    try 
    { 
     var updateResp = client.Update<Graph, Graph>(docPath, searchDescriptor => searchDescriptor 
      .Doc(graph)  
      .RetryOnConflict(4) 
      .Refresh(true) 
     ); 
    } 
} 

을 내 현재 구현에서는 내가 이전 Graph 객체를 대체하고있는 중이을 모두 볼 수 있습니다. 그러나 부분적으로 내 Graph 개체를 업데이트하고 싶습니다. Node 개체의 목록을 매개 변수로 보내려고합니다. NodeList에서 해당 개체를 찾아서 Node 개체 만 업데이트하십시오.

은 아마 다음과 같은 몇 가지, NodeList 때문에

public void UpdateGraph(string index, List<Node> node) 
{ 
    //Code here 
} 

답변

1

제공된 값이 기존 값을 대체 할 것 같은 부분 업데이트 할 수 없습니다하는 List<Node>입니다.

당신은 그러나 낙관적에 대한 GET 요청에서 버전 번호를 사용하여,

  • 가 Elasticsearch에 다시 응용 프로그램
  • 인덱스 변경된 문서의 변경을 기존의 문서를 얻을

    1. optimistic concurrency control을 사용할 수 있습니다 동시성

    다음과 같은 것이 작동합니다.

    var getResponse = client.Get<Graph>("graph-id"); 
    
    var graph = getResponse.Source; 
    var node = graph.NodeList.First(n => n.Id == "node-id"); 
    
    // make changes to the node 
    node.Name = "new name"; 
    node.EdgeList.First().Cost = 9.99; 
    
    var indexResponse = client.Index(graph, i => i 
        // specify the version from the get request 
        .Version(getResponse.Version) 
    ); 
    

    Graph이 get과 index 호출 사이에서 변경된 경우, 인덱스 호출시 409 응답이 리턴됩니다.

    NodeEdge을 각각 독립적으로 업데이트해야하는 경우 Parent/Child relationships으로 모델링하면 개체 그래프를 가져 와서 변경 사항을 색인하지 않고도 업데이트 할 수 있습니다.

  • 관련 문제