Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic Update for nested objects #598

Open
leandrocustodio opened this issue Jul 2, 2022 · 0 comments
Open

Atomic Update for nested objects #598

leandrocustodio opened this issue Jul 2, 2022 · 0 comments

Comments

@leandrocustodio
Copy link

Hello All,
I was wondering what should be the best way to handle atomic updates to nested fields. The SorlNet currently supports atomic updates for string, int, and, arrays. But when we are talking about nested objects I did not find anything related to atomic updates.

Do you consider a good idea to add another version to AtomicUpdateSpec that supports arrays of objects that should be handled as nested objects, for example:

Let's suppose that I'm indexing documents that represent Color Libraries with the following structure

public class Color {
  public int Id { get; set; }
  public string Name { get;set; }
}

public class ColorLibrary{
  public int Id { get; set; }
  public string Name { get; set; }
  public Color[] Colors { get;set; }
}

And I would like to update this current document

  var library = new ColorLibrary(){
    Id = 1,
    Name = "Awesome Colors",
    Colors = new(){
      new Color() { Id = 1, Name = "blue" },
      new Color() { Id = 2, Name = "red" },
    };
  };

My goal is to use the atomic update to update the nested list of colors, replacing, adding, or removing elements from this list. For example:

  var updatedColorList = new Color[] {
    new Color() { Id = 1, Name = "blue" },
    new Color() { Id = 2, Name = "dark red" },
    new Color() { Id = 3, Name = "black" },
    new Color() { Id = 4, Name = "White" },
  };

  var spec = specs.Add(new AtomicUpdateSpec(field.Key, AtomicUpdateType.Set, updatedColorList));

Considering this scenario I thought that could be relevant to update the AtomicUpdateSpec to support arrays of objects. This is the best way to implement this kind of operation, or did you have another suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant