Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiagobarradas/elasticsearch-bulkandsearch-dotnet
Elasticsearch Easy Bulk and Search for Dotnet
https://github.com/thiagobarradas/elasticsearch-bulkandsearch-dotnet
bulk demo dotnet dotnet-core dotnet-core2 easily easy elasticsearch high-level index search
Last synced: 2 days ago
JSON representation
Elasticsearch Easy Bulk and Search for Dotnet
- Host: GitHub
- URL: https://github.com/thiagobarradas/elasticsearch-bulkandsearch-dotnet
- Owner: ThiagoBarradas
- License: mit
- Created: 2019-02-05T13:34:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-24T16:58:55.000Z (over 2 years ago)
- Last Synced: 2024-11-10T23:56:35.038Z (5 days ago)
- Topics: bulk, demo, dotnet, dotnet-core, dotnet-core2, easily, easy, elasticsearch, high-level, index, search
- Language: C#
- Homepage: https://www.nuget.org/packages/Easy.Elasticsearch.BulkAndSearch/
- Size: 55.7 KB
- Stars: 6
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://barradas.visualstudio.com/Contributions/_apis/build/status/ThiagoBarradas.elasticsearch-bulkandsearch-dotnet?branchName=develop)](https://barradas.visualstudio.com/Contributions/_build/latest?definitionId=16&branchName=master)
[![NuGet Downloads](https://img.shields.io/nuget/dt/Easy.Elasticsearch.BulkAndSearch.svg)](https://www.nuget.org/packages/Easy.Elasticsearch.BulkAndSearch/)
[![NuGet Version](https://img.shields.io/nuget/v/Easy.Elasticsearch.BulkAndSearch.svg)](https://www.nuget.org/packages/Easy.Elasticsearch.BulkAndSearch/)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ThiagoBarradas_elasticsearch-bulkandsearch-dotnet&metric=alert_status)](https://sonarcloud.io/dashboard?id=ThiagoBarradas_elasticsearch-bulkandsearch-dotnet)# Elasticsearch Bulk and Search!
Elasticsearch Bulk and Search is a high level library to make easy basic query operations (get, search and scroll) and index operations (single index or bulk), besides paging, sorting and query buider.
# Sample
Sample Entity Class (Person)
```c#
public class Person
{
public string Id { get; set; }public DateTime CreateDate { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public static string GenerateIndexName(string defaultIndex, Person person)
{
var suffix = person.CreateDate.ToString("yyyy-MM");return $"{defaultIndex}-{suffix}";
}
}
```Init commad and query objects
```c#var elasticsearchOptions = new ElasticsearchOptions
{
WriteUrl = "http://localhost:9200",
ReadUrl = "http://localhost:9200",
DefaultTypeName = "docs",
TimeoutInSeconds = 60,
MaximumRetries = 5,
User = "user",
Pass = "pass"
};IElasticsearchCommand PersonCommand = new ElasticsearchCommand(elasticsearchOptions, Person.GenerateIndexName);
IElasticsearchQuery PersonQuery = new ElasticsearchQuery(elasticsearchOptions);```
Using GenerateIndexName you can customize index per document based on your properties (used to create timed index);
Basic commands
```c#
// bulk
var persons = new List
{
{ new Person { Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01) } },
{ new Person { Id = "8", Name = "Ralph Legal", Age = 29, CreateDate = new DateTime(2018, 12, 01) } },
{ new Person { Id = "9", Name = "James Bond", Age = 30, CreateDate = new DateTime(2018, 12, 10) } },
{ new Person { Id = "10", Name = "John Doe", Age = 54, CreateDate = new DateTime(2018, 11, 01) } },
{ new Person { Id = "11", Name = "Jow Troll Moon Do", Age = 58, CreateDate = new DateTime(2018, 05, 25) } }
};PersonCommand.Bulk(persons);
// upsert
var otherPerson = new Person { Id = "2", Name = "Rafael Barradas", Age = 25, CreateDate = new DateTime(2018, 12, 01) };PersonCommand.Upsert(otherPerson);
```Basic queries
```c#
// get by id
Person personX = PersonQuery.Get("8");
Person personY = PersonQuery.Get(4);// search
var searchOptions = new SearchOptions
{
Page = 1,
Size = 1,
SortField = "name.keyword",
SortMode = SortMode.ASC
};var query = Query.DateRange(i => i.Field("createDate").LessThan("2018-12-01"));
var searchResult = PersonQuery.Search(query, searchOptions);
// scroll
var scrollOptions = new ScrollOptions
{
Scroll = "1m",
Size = 2,
SortField = "name.keyword",
SortMode = BulkAndSearch.Models.SortMode.ASC
};List scrollPersons = new List();
var scrollResult = PersonQuery.Scroll(query, scrollOptions);
while (scrollResult.Items.Any())
{
scrollPersons.AddRange(scrollResult.Items);scrollResult = PersonQuery.Scroll(query, scrollOptions);
}
```When some error occurred, an exception is thrown;
## Install via NuGet
```
PM> Install-Package Easy.Elasticsearch.BulkAndSearch
```## How can I contribute?
Please, refer to [CONTRIBUTING](.github/CONTRIBUTING.md)## Found something strange or need a new feature?
Open a new Issue following our issue template [ISSUE_TEMPLATE](.github/ISSUE_TEMPLATE.md)## Changelog
See in [nuget version history](https://www.nuget.org/packages/Elasticsearch.BulkAndSearch)## Did you like it? Please, make a donate :)
if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.
BTC Wallet: `1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX`
![1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX](https://i.imgur.com/mN7ueoE.png)