Last active
August 19, 2018 22:47
-
-
Save QiMata/4b95bbb30c163fb00d3b1922d27acfd0 to your computer and use it in GitHub Desktop.
The Controller Endpoint for using a Kendo Grid against ElasticSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore; | |
using Nest; | |
public class GridController : Controller | |
{ | |
private readonly ElasticClient _elasticClient; | |
public GridController() | |
{ | |
//Initalize ElasticClient | |
} | |
[HttpPost] | |
public async Task<IActionResult> PostRequest([FromBody]RequestDto request) | |
{ | |
CompositeFilterMapper compositeFilterMapper = new CompositeFilterMapper(); | |
//Grab a page from elastic | |
selector = search => | |
search.Index("your-index") | |
.From(request.Page.Skip) | |
.Size(request.Page.Take) | |
.Query(q => | |
compositeFilterMapper.GetQueryContainer(q)); | |
var searchResponse = _elasticClient.Search(selector); | |
return Ok(new ResponseDto | |
{ | |
Results = searchResponse.Documents, | |
Count = searchResponse.Total | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResponseDto<T> | |
{ | |
public IEnumerable<T> Results { get; set; } | |
public long Count { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment