SearchQuery

open class SearchQuery<S : BaseDocSource>(docSourceFactory: (obj: Deserializer.ObjectCtx) -> S, query: QueryExpression? = null, params: Params = Params()) : BaseSearchQuery<S, SearchQuery<S>>

An asynchronous version of search query.

Constructors

Link copied to clipboard
fun <S : BaseDocSource> SearchQuery(docSourceFactory: (obj: Deserializer.ObjectCtx) -> S, query: QueryExpression? = null, params: Params = Params())

Types

Link copied to clipboard
object CLEAR
Link copied to clipboard
object Companion
Link copied to clipboard
data class Count(val query: QueryExpression?, val filters: List<QueryExpression>, val postFilters: List<QueryExpression>, val terminateAfter: Int?, val params: Params) : PreparedSearchQuery

A prepared search query used for delete by count API.

Link copied to clipboard
data class Delete(val query: QueryExpression?, val filters: List<QueryExpression>, val postFilters: List<QueryExpression>, val terminateAfter: Int?, val params: Params) : PreparedSearchQuery

A prepared search query used for delete by query API.

Link copied to clipboard
data class Search<out S : BaseDocSource>(val docSourceFactory: (obj: Deserializer.ObjectCtx) -> S, val query: QueryExpression?, val filters: List<QueryExpression>, val postFilters: List<QueryExpression>, val aggregations: Map<String, Aggregation<*>>, val rescores: List<Rescore>, val sorts: List<Sort>, val trackScores: Boolean?, val trackTotalHits: Boolean?, val source: Source?, val fields: List<FieldFormat>, val docvalueFields: List<FieldFormat>, val storedFields: List<FieldOperations<*>>, val scriptFields: Map<String, Script>, val runtimeMappings: Map<String, BoundRuntimeField<*>>, val size: Int?, val from: Int?, val terminateAfter: Int?, val extensions: List<SearchExt>, val timeout: Duration?, val params: Params) : PreparedSearchQuery

A prepared search query is a public read-only view to a search query. Mainly it is used to compile a search query.

Link copied to clipboard
data class Update(val query: QueryExpression?, val filters: List<QueryExpression>, val postFilters: List<QueryExpression>, val terminateAfter: Int?, val script: Script?, val params: Params) : PreparedSearchQuery

A prepared search query used for update by query API.

Functions

Link copied to clipboard

Clears the existing aggregations.

fun aggs(vararg aggregations: Pair<String, Aggregation<*>>): SearchQuery<S>
fun aggs(aggregations: Map<String, Aggregation<*>>): SearchQuery<S>

Adds aggregations to the existing query aggregations.

Link copied to clipboard
open fun beforeExecute()

Method is called before query execution. Can be overriden in subclasses of SearchQuery.

Link copied to clipboard

Clones this search query builder.

Link copied to clipboard
suspend fun count(index: ElasticsearchIndex, params: Params? = null): CountResult

Retrieves a number of hits for the search query using an index.

Link copied to clipboard
suspend fun delete(index: ElasticsearchIndex, refresh: Refresh? = null, conflicts: Conflicts? = null, maxDocs: Int? = null, scrollSize: Int? = null, params: Params? = null): DeleteByQueryResult

Update by query API.

Link copied to clipboard
suspend fun deleteAsync(index: ElasticsearchIndex, refresh: Refresh? = null, conflicts: Conflicts? = null, maxDocs: Int? = null, scrollSize: Int? = null, params: Params? = null): AsyncResult<DeleteByQueryPartialResult, DeleteByQueryResult?>
Link copied to clipboard

Clears current search query doc value fields.

fun docvalueFields(vararg fields: FieldFormat): SearchQuery<S>

Adds fields to the search query doc value fields list.

Link copied to clipboard
suspend fun execute(index: ElasticsearchIndex, params: Params? = null): SearchQueryResult<S>

Alias of SearchQuery.search. Executes the search query using an index.

Link copied to clipboard

Clears current search query extensions.

fun ext(vararg extensions: SearchExt): SearchQuery<S>
fun ext(extensions: List<SearchExt>): SearchQuery<S>

Adds extensions to the search query extensions list.

Link copied to clipboard

Clears current search query retrieval fields.

fun fields(vararg fields: FieldFormat): SearchQuery<S>

Adds fields to the search query retrieval fields list.

Link copied to clipboard

Clears the existing filters.

fun filter(vararg filters: QueryExpression): SearchQuery<S>

Combines all the filter expressions together and wraps the existing query using the dev.evo.elasticmagic.query.Bool query expression.

Link copied to clipboard
fun from(from: Int?): SearchQuery<S>

Sets a number of hits to skip in a search result.

Link copied to clipboard

Clears the existing post filters.

fun postFilter(vararg filters: QueryExpression): SearchQuery<S>

Filter expressions in the post filter will be applied after the aggregations are calculated. Useful for building faceted filtering.

Link copied to clipboard
fun prepareCount(params: Params? = null): SearchQuery.Count
Link copied to clipboard
Link copied to clipboard
fun prepareSearch(params: Params? = null): SearchQuery.Search<S>

Makes an immutable view of the search query. Be careful when using this method.

Link copied to clipboard
fun prepareUpdate(script: Script? = null, params: Params? = null): SearchQuery.Update
Link copied to clipboard

Replaces main query expression.

Link copied to clipboard
inline fun <N : QueryExpression> queryNode(handle: NodeHandle<N>, block: (N) -> N): SearchQuery<S>

Allows to replace a specific query expression node using a handle of the node.

Link copied to clipboard
fun requestCache(requestCache: Boolean?): SearchQuery<S>

Enables/disables a request cache of the search query.

Link copied to clipboard

Clears the existing rescorers.

fun rescore(vararg rescores: Rescore): SearchQuery<S>

Adds rescores to the existing query rescorers. Rescoring is executed after post filter phase.

fun rescore(rescores: List<Rescore>): SearchQuery<S>
Link copied to clipboard
fun routing(routing: Long?): SearchQuery<S>

Sets a routing parameter of the search query. A search request will be send to a specific shard.

fun routing(routing: String?): SearchQuery<S>

Updates search type of the search query.

Link copied to clipboard

Clears current search query runtime fields.

Adds fields to the search query runtime fields list.

Link copied to clipboard

Clears current search query stored fields.

fun scriptFields(vararg fields: Pair<String, Script>): SearchQuery<S>

Adds fields to the search query script fields list.

Link copied to clipboard
suspend fun search(index: ElasticsearchIndex, params: Params? = null): SearchQueryResult<S>

Executes the search query using an index.

Link copied to clipboard
fun searchParams(vararg params: Pair<String, Any?>): SearchQuery<S>

Updates search parameters.

Link copied to clipboard
fun searchType(searchType: SearchType?): SearchQuery<S>

Updates search type of the search query.

Link copied to clipboard
fun seqNoPrimaryTerm(seqNoPrimaryTerm: Boolean?): SearchQuery<S>

Specifies if a sequence number and a primary term should be returned within a hit.

Link copied to clipboard
fun setTimeout(timeout: Duration?): SearchQuery<S>

Sets a timeout for the search query.

Link copied to clipboard
fun size(size: Int?): SearchQuery<S>

Sets a maximum number of hits in a search result.

Link copied to clipboard

Clears the existing sorts.

fun sort(vararg sorts: Sort): SearchQuery<S>

Adds sorts to the existing query sorting expressions.

fun sort(sorts: List<Sort>): SearchQuery<S>

Adds sorts from a list to the existing query sorting expressions.

Link copied to clipboard

Clears source filtering values that were previously set.

fun source(vararg includes: FieldOperations<*>): SearchQuery<S>

Adds includes field lists to the document source fields filtering.

fun source(enable: Boolean): SearchQuery<S>

Disables or enables document's source filtering.

fun source(includes: List<FieldOperations<*>> = emptyList(), excludes: List<FieldOperations<*>> = emptyList()): SearchQuery<S>

Adds includes and excludes field lists to the document source fields filtering.

Link copied to clipboard
fun stats(tag: String?): SearchQuery<S>

Marks the search query with a tag so it is possible to collect search query statistics by tags.

Link copied to clipboard

Clears current search query stored fields.

fun storedFields(vararg fields: FieldOperations<*>): SearchQuery<S>

Adds fields to the search query stored fields list.

Link copied to clipboard
fun terminateAfter(terminateAfter: Int?): SearchQuery<S>

Sets a maximum number of matched documents per shard after which the query should be terminated.

Link copied to clipboard
fun trackScores(trackScores: Boolean?): SearchQuery<S>

If trackScores is true forces computing scores even when sorting on a field.

Link copied to clipboard
fun trackTotalHits(trackTotalHits: Boolean?): SearchQuery<S>

When trackTotalHits is true the search query will always count the total number of hits that match the query.

Link copied to clipboard
suspend fun update(index: ElasticsearchIndex, script: Script? = null, refresh: Refresh? = null, conflicts: Conflicts? = null, maxDocs: Int? = null, scrollSize: Int? = null, params: Params? = null): UpdateByQueryResult

Update by query API.

Link copied to clipboard
suspend fun updateAsync(index: ElasticsearchIndex, script: Script? = null, refresh: Refresh? = null, conflicts: Conflicts? = null, maxDocs: Int? = null, scrollSize: Int? = null, params: Params? = null): AsyncResult<UpdateByQueryPartialResult, UpdateByQueryResult?>
Link copied to clipboard
fun version(version: Boolean?): SearchQuery<S>

Enables/disables a document version to be returned within a hit.