Created
March 8, 2022 16:30
-
-
Save awswithdotnet/9769d1fbd4402df7e6f65df9991a9fc2 to your computer and use it in GitHub Desktop.
elasticsearch DataSearch Program Complete
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
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