Query examples

edit

This page demonstrates how to perform a search request.

Fluent API

edit
var response = await client
	.SearchAsync<Person>(search => search
		.Index("persons")
		.Query(query => query
			.Term(term => term
				.Field(x => x.FirstName)
				.Value("Florian")
			)
		)
		.Size(10)
	);

Object initializer API

edit
var response = await client
	.SearchAsync<Person>(new SearchRequest<Person>("persons")
	{
		Query = Query.Term(new TermQuery(Infer.Field<Person>(x => x.FirstName))
		{
			Value = "Florian"
		}),
		Size = 10
	});

Consume the response

edit
foreach (var person in response.Documents)
{
	Console.WriteLine(person.FirstName);
}