(Quick Reference)
search
Purpose
Search through indices for the specified search query.
The returned result may contain different type of domain.
Examples
def highlighter = {
field 'message', 0, 0
preTags '<strong>'
postTags '</strong>'
}def res = elasticSearchService.search("${params.query}")
def res = elasticSearchService.search("${params.query}", [from:0, size:30, highlighter:highlighter])
def res = elasticSearchService.search(){
queryString("${params.query}")
}
def res = elasticSearchService.search(from:0, size:30, indices:"tweet") {
queryString("${params.query}")
}
Description
search
signatures:
def search(Closure query, Map params)
def search(Map params, Closure query)
def search(String query, Map params)
Parameters
query
- The search query.
- As a
String
, the query is parsed by the Lucene query parser for advanced searching.
- Can also be a
Closure
, using the Groovy Query DSL of the ElasticSearch groovy client.
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
)
indices
- Limit the search only to the specified indices (may be a String
, or Collection
of String
)
types
- Limit the search only to the specified types (domains) (may be a String
, or Collection
of String
).
highlight
- 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.