(Quick Reference)

search

Purpose

Search through an index for the specified search query. The returned result only contains hits for the correponding domain.

Only domains that are root-mapped have this method injected.

Examples

def highlighter = {
  field 'message', 0, 0
  preTags '<strong>'
  postTags '</strong>'
}

def res = MyDomain.search("${params.query}") def res = MyDomain.search("${params.query}", [from:0, size:30, highlighter:highlighter]) def res = MyDomain.search(){ queryString("${params.query}") } def res = MyDomain.search(from:0, size:30) { queryString("${params.query}") }

Description

search signature:

def search(Closure query, Map params)
def search(Map params, Closure query)
def search(String query, Map params)

Parameters

  • query - The search query. You may use one or more terms to look for, or use the Lucene syntax for advanced searching.
  • params - A list of additional parameters to customize the searching process
    • from and size - From (hit) and the size (number of hits) to return.
    • sort - Sort based on different fields including ElasticSearch's internal ones (like _score)
    • highlighter - A Closure containing the highlighting settings.

Returned value

Return a Map containing:

  • a total entry, representing the total number of hits found
  • a searchResults entry, containing the hits
  • a scores entry, containing the hits' scores.
  • a highlight entry if the highlighter parameter was set.