Query examples
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Query examples
editThis page demonstrates how to perform a search request.
Fluent API
editvar 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
editvar 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
editforeach (var person in response.Documents)
{
Console.WriteLine(person.FirstName);
}