|
| 1 | +# Elasticsearch plugin for Workflow Core |
| 2 | + |
| 3 | +A search index plugin for Workflow Core backed by Elasticsearch, enabling you to index your workflows and search against the data and state of them. |
| 4 | + |
| 5 | +## Installing |
| 6 | + |
| 7 | +Install the NuGet package "WorkflowCore.Providers.Elasticsearch" |
| 8 | + |
| 9 | +Using Nuget package console |
| 10 | +``` |
| 11 | +PM> Install-Package WorkflowCore.Providers.Elasticsearch |
| 12 | +``` |
| 13 | + |
| 14 | +Using .NET CLI |
| 15 | +``` |
| 16 | +dotnet add package WorkflowCore.Providers.Elasticsearch |
| 17 | +``` |
| 18 | + |
| 19 | + |
| 20 | +## Configuration |
| 21 | + |
| 22 | +Use the `.UseElasticsearch` extension method on `IServiceCollection` when building your service provider |
| 23 | + |
| 24 | +```C# |
| 25 | +using Nest; |
| 26 | +... |
| 27 | +services.AddWorkflow(cfg => |
| 28 | +{ |
| 29 | + ... |
| 30 | + cfg.UseElasticsearch(new ConnectionSettings(new Uri("http://localhost:9200")), "index_name"); |
| 31 | +}); |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +Inject the `ISearchIndex` service into your code and use the `Search` method. |
| 37 | + |
| 38 | +``` |
| 39 | +Search(string terms, int skip, int take, params SearchFilter[] filters) |
| 40 | +``` |
| 41 | + |
| 42 | +#### terms |
| 43 | + |
| 44 | +A whitespace separated string of search terms, an empty string will match everything. |
| 45 | +This will do a full text search on the following default fields |
| 46 | + * Reference |
| 47 | + * Description |
| 48 | + * Status |
| 49 | + * Workflow Definition |
| 50 | + |
| 51 | + In addition you can search data within your own custom data object if it implements `ISearchable` |
| 52 | + |
| 53 | + ```c# |
| 54 | + using WorkflowCore.Interfaces; |
| 55 | + ... |
| 56 | + public class MyData : ISearchable |
| 57 | +{ |
| 58 | + public string StrValue1 { get; set; } |
| 59 | + public string StrValue2 { get; set; } |
| 60 | + |
| 61 | + public IEnumerable<string> GetSearchTokens() |
| 62 | + { |
| 63 | + return new List<string>() |
| 64 | + { |
| 65 | + StrValue1, |
| 66 | + StrValue2 |
| 67 | + }; |
| 68 | + } |
| 69 | +} |
| 70 | + ``` |
| 71 | + |
| 72 | + ##### Examples |
| 73 | + |
| 74 | + Search all fields for "puppies" |
| 75 | + ```c# |
| 76 | + searchIndex.Search("puppies", 0, 10); |
| 77 | + ``` |
| 78 | + |
| 79 | +#### skip & take |
| 80 | + |
| 81 | +Use `skip` and `take` to page your search results. Where `skip` is the result number to start from and `take` is the page size. |
| 82 | + |
| 83 | +#### filters |
| 84 | + |
| 85 | +You can also supply a list of filters to apply to the search, these can be applied to both the standard fields as well as any field within your custom data objects. |
| 86 | +There is no need to implement `ISearchable` on your data object in order to use filters against it. |
| 87 | + |
| 88 | +The following filter types are available |
| 89 | + * ScalarFilter |
| 90 | + * DateRangeFilter |
| 91 | + * NumericRangeFilter |
| 92 | + * StatusFilter |
| 93 | + |
| 94 | + These exist in the `WorkflowCore.Models.Search` namespace. |
| 95 | + |
| 96 | + ##### Examples |
| 97 | + |
| 98 | + Filtering by reference |
| 99 | + ```c# |
| 100 | + using WorkflowCore.Models.Search; |
| 101 | + ... |
| 102 | + |
| 103 | + searchIndex.Search("", 0, 10, ScalarFilter.Equals(x => x.Reference, "My Reference")); |
| 104 | + ``` |
| 105 | + |
| 106 | + Filtering by workflows started after a date |
| 107 | + ```c# |
| 108 | + searchIndex.Search("", 0, 10, DateRangeFilter.After(x => x.CreateTime, startDate)); |
| 109 | + ``` |
| 110 | + |
| 111 | + Filtering by workflows completed within a period |
| 112 | + ```c# |
| 113 | + searchIndex.Search("", 0, 10, DateRangeFilter.Between(x => x.CompleteTime, startDate, endDate)); |
| 114 | + ``` |
| 115 | + |
| 116 | + Filtering by workflows in a state |
| 117 | + ```c# |
| 118 | + searchIndex.Search("", 0, 10, StatusFilter.Equals(WorkflowStatus.Complete)); |
| 119 | + ``` |
| 120 | + |
| 121 | + Filtering against your own custom data class |
| 122 | + ```c# |
| 123 | + |
| 124 | + class MyData |
| 125 | + { |
| 126 | + public string Value1 { get; set; } |
| 127 | + public int Value2 { get; set; } |
| 128 | + } |
| 129 | + |
| 130 | + searchIndex.Search("", 0, 10, ScalarFilter.Equals<MyData>(x => x.Value1, "blue moon")); |
| 131 | + searchIndex.Search("", 0, 10, NumericRangeFilter.LessThan<MyData>(x => x.Value2, 5)) |
| 132 | + ``` |
0 commit comments