[ad_1]
I’m trying to call controller method which internally calls an Elasticsearch service inside angular service file. I don’t know how to proceed and get the data from Elasticsearch using Angular and .NET
Here is my ElasticSearchController methods code.
public class ElasticsearchController : ControllerBase
{
private readonly IElasticClient _elasticClient;
public ElasticsearchController(IElasticClient elasticClient)
{
_elasticClient = elasticClient;
}
[HttpGet(Name = "GetEvents")]
public async Task<IActionResult> Get(string keyword)
{
var results = await _elasticClient.SearchAsync<Event>(
s => s.Index("event").Query(
q => q.QueryString(
d => d.Query('*' + keyword + '*')
)
).Size(1000)
);
return Ok(results.Documents.ToList());
}
}
My Elasticserachservice which resides under src/app/services/elasticsearch.service.ts code looks like
@Injectable({
providedIn: 'root'
})
export class ElasticsearchService {
constructor(private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) {
}
public get(): Observable<any> {
return this.http.get<any[]>(this.baseUrl + 'elasticsearch');
}
}
[ad_2]