[U] public async Task Urls() { var project = new Project { Name = "NEST" }; await POST("/project/project") .Fluent(c => c.Index(project, i => i.Id(null))) .Request(c => c.Index(new IndexRequest<Project>("project", "project") { Document = project })) .FluentAsync(c => c.IndexAsync(project, i => i.Id(null))) .RequestAsync(c => c.IndexAsync(new IndexRequest<Project>(typeof(Project), TypeName.From<Project>()) { Document = project })) ; await POST("/project/project") .Fluent(c => c.Index(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))) .Request(c => c.Index(new IndexRequest<object>("project", "project") { Document = new { } })) .FluentAsync(c => c.IndexAsync(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)))) .RequestAsync(c => c.IndexAsync(new IndexRequest<object>(typeof(Project), TypeName.From<Project>()) { Document = new { } })) ; await PUT("/project/project/NEST") .Fluent(c => c.Index(project)) .Request(c => c.Index(new IndexRequest<Project>("project", "project", "NEST") { Document = project })) .Request(c => c.Index(new IndexRequest<Project>(project))) .FluentAsync(c => c.IndexAsync(project)) .RequestAsync(c => c.IndexAsync(new IndexRequest<Project>(project))) ; }
//** if you have an instance of your document you can use it as well generate document paths */ [U] public void FromObject() { var project = new Project { Name = "hello-world" }; /** here we create a new document path based on a Project */ IDocumentPath path = new DocumentPath<Project>(project); Expect("project").WhenSerializing(path.Index); Expect("project").WhenSerializing(path.Type); Expect("hello-world").WhenSerializing(path.Id); /** You can still override the inferred index and type name*/ path = new DocumentPath<Project>(project).Type("project1"); Expect("project1").WhenSerializing(path.Type); path = new DocumentPath<Project>(project).Index("project1"); Expect("project1").WhenSerializing(path.Index); /** there is also a static way to describe such paths */ path = DocumentPath<Project>.Id(project); Expect("project").WhenSerializing(path.Index); Expect("project").WhenSerializing(path.Type); Expect("hello-world").WhenSerializing(path.Id); DocumentPath<Project> p = project; }
[U] public async Task Urls() { var project = new Project { Name = "NEST" }; await PUT("/project/project/1/_create") .Fluent(c => c.Create<object>(new { }, i => i.Index(typeof(Project)).Type(typeof(Project)).Id(1))) .Request(c => c.Create(new CreateRequest<object>("project", "project", 1) { Document = new { } })) .FluentAsync(c => c.CreateAsync<object>(new {}, i => i.Index(typeof(Project)).Type(typeof(Project)).Id(1))) .RequestAsync(c => c.CreateAsync(new CreateRequest<object>(IndexName.From<Project>(), TypeName.From<Project>(), 1) { Document = new { } })) ; await PUT("/project/project/NEST/_create") .Fluent(c => c.Create(project)) .Request(c => c.Create(new CreateRequest<Project>(project))) .Request(c => c.Create(new CreateRequest<Project>(project, "project", "project", "NEST") { Document = project })) .FluentAsync(c => c.CreateAsync(project)) .RequestAsync(c => c.CreateAsync(new CreateRequest<Project>(project))) .RequestAsync(c => c.CreateAsync(new CreateRequest<Project>(project, "project", "project", "NEST") { Document = project })) ; await PUT("/different-projects/project/elasticsearch/_create") .Request(c => c.Create(new CreateRequest<Project>("different-projects", "project", "elasticsearch") { Document = project })) .Request(c => c.Create(new CreateRequest<Project>(project, "different-projects", "project", "elasticsearch"))) .RequestAsync(c => c.CreateAsync(new CreateRequest<Project>(project, "different-projects", "project", "elasticsearch"))) .RequestAsync(c => c.CreateAsync(new CreateRequest<Project>("different-projects", "project", "elasticsearch") { Document = project })) ; }
[U] public async Task Urls() { var project = new Project { Name = "NEST" }; await POST("/project/project/NEST/_explain") .Fluent(c => c.Explain<Project>("NEST", e => e.Query(q=>q.MatchAll()))) .Request(c => c.Explain(new ExplainRequest<Project>("project", "project", "NEST") {})) .FluentAsync(c => c.ExplainAsync<Project>(project, e=>e.Query(q=>q.MatchAll()))) .RequestAsync(c => c.ExplainAsync(new ExplainRequest<Project>("NEST"))) ; }
[U] public void UsingWithRequests() { var project = new Project { Name = "hello-world" }; /** Here we can see and example how DocumentPath helps your describe your requests more tersely */ var request = new IndexRequest<Project>(2) { Document = project }; request = new IndexRequest<Project>(project) { }; /** when comparing with the full blown constructor and passing document manually * DocumentPath<T>'s benefits become apparent. */ request = new IndexRequest<Project>(IndexName.From<Project>(), TypeName.From<Project>(), 2) { Document = project }; }
/** === An example with requests */ [U] public void UsingWithRequests() { /* Given the following CLR type that describes a document */ var project = new Project { Name = "hello-world" }; /** we can see an example of how `DocumentPath` helps your describe your requests more tersely */ var request = new IndexRequest<Project>(2) { Document = project }; request = new IndexRequest<Project>(project) { }; /** when comparing with the full blown constructor and passing document manually, * `DocumentPath<T>`'s benefits become apparent. */ request = new IndexRequest<Project>(IndexName.From<Project>(), TypeName.From<Project>(), 2) { Document = project }; }
public async Task Urls() { var id = "name-of-doc"; var index = "myindex"; await GET($"/{index}/project/{id}/_termvectors") .Fluent(c=>c.TermVectors<Project>(t => t.Index(index).Id(id))) .Request(c=>c.TermVectors(new TermVectorsRequest<Project>(index, typeof(Project), id))) .FluentAsync(c=>c.TermVectorsAsync<Project>(t => t.Index(index).Id(id))) .RequestAsync(c=>c.TermVectorsAsync(new TermVectorsRequest<Project>(index, typeof(Project), id))) ; await GET($"/project/project/{id}/_termvectors") .Fluent(c=>c.TermVectors<Project>(t => t.Id(id))) .Request(c=>c.TermVectors(new TermVectorsRequest<Project>(id))) .FluentAsync(c=>c.TermVectorsAsync<Project>(t => t.Id(id))) .RequestAsync(c=>c.TermVectorsAsync(new TermVectorsRequest<Project>(id))) ; await GET($"/{index}/project/{id}/_termvectors") .Fluent(c=>c.TermVectors<Project>(t => t.Index(index).Id(id))) .Request(c=>c.TermVectors(new TermVectorsRequest<Project>(index, typeof(Project), id))) .FluentAsync(c=>c.TermVectorsAsync<Project>(t => t.Index(index).Id(id))) .RequestAsync(c=>c.TermVectorsAsync(new TermVectorsRequest<Project>(index, typeof(Project), id))) ; var document = new Project { Name = "foo" }; await POST($"/{index}/project/_termvectors") .Fluent(c => c.TermVectors<Project>(t => t.Index(index).Document(document))) .Request(c => c.TermVectors(new TermVectorsRequest<Project>(new DocumentPath<Project>(document).Index(index)))) .FluentAsync(c => c.TermVectorsAsync<Project>(t => t.Index(index).Document(document))) .RequestAsync(c => c.TermVectorsAsync(new TermVectorsRequest<Project>(new DocumentPath<Project>(document).Index(index)))) ; await POST($"/project/project/_termvectors") .Fluent(c=>c.TermVectors<Project>(t => t.Document(document))) .Request(c=>c.TermVectors(new TermVectorsRequest<Project>(document))) .FluentAsync(c=>c.TermVectorsAsync<Project>(t => t.Document(document))) .RequestAsync(c=>c.TermVectorsAsync(new TermVectorsRequest<Project>(document))) ; }
[U] public async Task Urls() { var id = "name-of-doc"; var index = "indexx"; await POST($"/{index}/project/{id}/_percolate") .Fluent(c=>c.Percolate<Project>(s=>s.Id(id).Index(index))) .Request(c=>c.Percolate(new PercolateRequest<Project>(index, typeof(Project), id))) .FluentAsync(c=>c.PercolateAsync<Project>(s=> s.Id(id).Index(index))) .RequestAsync(c=>c.PercolateAsync(new PercolateRequest<Project>(index, typeof(Project), id))) ; await POST($"/project/project/{id}/_percolate") .Fluent(c=>c.Percolate<Project>(s=>s.Id(id))) .Request(c=>c.Percolate(new PercolateRequest<Project>(id))) .FluentAsync(c=>c.PercolateAsync<Project>(s=>s.Id(id))) .RequestAsync(c=>c.PercolateAsync(new PercolateRequest<Project>(id))) ; await POST($"/{index}/project/_percolate") .Fluent(c=>c.Percolate<Project>(s=>s.Index(index))) .Request(c=>c.Percolate(new PercolateRequest<Project>(index, typeof(Project)))) .FluentAsync(c=>c.PercolateAsync<Project>(s=> s.Index(index))) .RequestAsync(c=>c.PercolateAsync(new PercolateRequest<Project>(index, typeof(Project)))) ; await POST($"/project/project/_percolate") .Fluent(c=>c.Percolate<Project>(s=>s)) .Request(c=>c.Percolate(new PercolateRequest<Project>())) .FluentAsync(c=>c.PercolateAsync<Project>(s=>s)) .RequestAsync(c=>c.PercolateAsync(new PercolateRequest<Project>())) ; var document = new Project { Name = "foo" }; await POST($"/project/project/_percolate") .Fluent(c=>c.Percolate<Project>(s=>s.Document(document))) .Request(c=>c.Percolate(new PercolateRequest<Project>(document))) .FluentAsync(c=>c.PercolateAsync<Project>(s=>s.Document(document))) .RequestAsync(c=>c.PercolateAsync(new PercolateRequest<Project>(document))) ; }
public async Task Urls() { var document = new Project { Name = "foo" }; await POST($"/project/project/foo/_update") .Fluent(c => c.Update<Project>(document, u => u)) .Request(c => c.Update(new UpdateRequest<Project, object>(document))) .FluentAsync(c => c.UpdateAsync<Project>(document, u => u)) .RequestAsync(c => c.UpdateAsync(new UpdateRequest<Project, object>(document))) ; var otherId = "other-id"; await POST($"/project/project/{otherId}/_update") .Fluent(c => c.Update<Project>(otherId, u => u)) .Request(c => c.Update(new UpdateRequest<Project, object>(typeof(Project), typeof(Project), otherId))) .FluentAsync(c => c.UpdateAsync<Project>(otherId, u => u)) .RequestAsync(c => c.UpdateAsync(new UpdateRequest<Project, object>(typeof(Project), typeof(Project), otherId))) ; var otherIndex = "other-index"; await POST($"/{otherIndex}/project/{otherId}/_update") .Fluent(c => c.Update<Project>(otherId, u => u.Index(otherIndex))) .Request(c => c.Update(new UpdateRequest<Project, object>(otherIndex, typeof(Project), otherId))) .FluentAsync(c => c.UpdateAsync<Project>(otherId, u => u.Index(otherIndex))) .RequestAsync(c => c.UpdateAsync(new UpdateRequest<Project, object>(otherIndex, typeof(Project), otherId))) ; var otherType = "other-type"; await POST($"/{otherIndex}/{otherType}/{otherId}/_update") .Fluent(c => c.Update<Project>(otherId, u => u.Index(otherIndex).Type(otherType))) .Request(c => c.Update(new UpdateRequest<Project, object>(otherIndex, otherType, otherId))) .FluentAsync(c => c.UpdateAsync<Project>(otherId, u => u.Index(otherIndex).Type(otherType))) .RequestAsync(c => c.UpdateAsync(new UpdateRequest<Project, object>(otherIndex, otherType, otherId))) ; }