Skip to content

Instantly share code, notes, and snippets.

@awswithdotnet
Created March 8, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awswithdotnet/9769d1fbd4402df7e6f65df9991a9fc2 to your computer and use it in GitHub Desktop.
Save awswithdotnet/9769d1fbd4402df7e6f65df9991a9fc2 to your computer and use it in GitHub Desktop.
elasticsearch DataSearch Program Complete
namespace DataSearch
{
class Program
{
static async Task Main(string[] args)
{
IElasticSearchConnectionSettingsFactory elasticSearchConnectionSettingsFactory = new ElasticSearchStaticConnectionSettingsFactory();
IElasticSearchClientFactory elasticSearchClientFactory = new ElasticSearchClientFactory(elasticSearchConnectionSettingsFactory);
IElasticClient client = elasticSearchClientFactory.GetClient();
var searchRequest = new SearchRequest<Vehicle>()
{
From = 0,
Size = 1,
Query = new MatchQuery
{
Field = Infer.Field<Vehicle>(f => f.Make),
Query = "BMW"
}
};
var searchResponse = await client.SearchAsync<Vehicle>(searchRequest);
Vehicle vehicle = searchResponse.Documents.FirstOrDefault();
Console.WriteLine("Vehicle Id: " + vehicle.Id);
Console.WriteLine("Year: " + vehicle.Year);
Console.WriteLine("Make: " + vehicle.Make);
Console.WriteLine("Model: " + vehicle.Model);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment