Skip to content

Querying

To build a search query use a SearchQuery builder.

In these samples we will utilize following document:


Query

You can pass a query to SearchQuery directly via its constructor:


Also it is possible to replace existing query using a query method:


See full list of available query expressions.

Cloning

In the last example q and q2 variables point to the same object. For efficiency all SearchQuery methods modify current instance and return it for chaining method calls.

If you want to get independent query instance you should clone it explicitly:


Now you can modify clonedQuery without touching its ancestor q.

Filtering

Using filter method you can filter your query. All filters passed to the filter method will be combined using AND operation.


See Query Filter Context

Sorting

sort method has 2 flavors:

  • a shortcut that accepts document fields
  • and full-featured version accepting Sort expressions

See:

Aggregations

Use aggs method to define aggregations:


See Search Aggregations

Query Nodes

Sometimes you don't know final form of your query when creating it. For such a usecase it is possible to replace parts of the query after creation using special query expressions and queryNode method: