Skip to content

Commit

Permalink
Add doc for atomic update
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMrDexter committed May 11, 2023
1 parent ce3c4b2 commit 26f66cb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Documentation/Atomic-updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Atomic updates
Atomic updates can be used update only specific fields in document. This can help speed up indexing in certain use cases. With SolrNet, atomic updates can be done using `AtomicUpdate()` methods.

Each individual update is defined by the `AtomicUpdateSpec`, which has below fields
- `field` - Name of field
- `type` - Type of operation to be done
- `value` - Value to be updated

`AtomicUpdate()` method requests update on a single document, which can be identified by the first parameter to the method.

### Example

Consider a sample document of type `Product` as below,

```C#
public class Product {
[SolrUniqueKey("id")]
public string Id { get; set; }

[SolrField("cat")]
public ICollection<string> Categories { get; set; }

[SolrField("sold")]
public int SoldCount { get; set; }

[SolrField("inStock")]
public int InStock { get; set; }
}
```

Below code can be used to update a document with id `mydoc` by adding a new category `toys` and to increment the `SoldCount` by 14 and decrement `InStock` count by 6.

```
ISolrOperations<Product> solr = ...
solr.AtomicUpdate("mydoc",
new[]
{
new AtomicUpdateSpec("cat", AtomicUpdateType.Add, "toys"),
new AtomicUpdateSpec("sold", AtomicUpdateType.Inc, 14),
new AtomicUpdateSpec("inStock", AtomicUpdateType.Inc, -6),
});
```

### Reference

See the [Solr wiki](https://solr.apache.org/guide/solr/latest/indexing-guide/partial-document-updates.html#atomic-updates) for more information.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The easiest way to get going is to use our NuGet packages:
* [Mapping](Documentation/Mapping.md)
* [Initialization](Documentation/Initialization.md)
* [Create/Update/Delete](Documentation/CRUD.md)
* [Atomic updates](Documentation/Atomic-updates.md)
* [Querying](Documentation/Querying.md)
* [Faceting](Documentation/Facets.md)
* [Highlighting](Documentation/Highlighting.md)
Expand Down

0 comments on commit 26f66cb

Please sign in to comment.