PyES Documentation
latest
  • Getting Started
  • Frequently Asked Questions
  • API Reference
  • Change history
  • Interesting Links
  • ES Reference
    • Setup
    • Api
    • Query Dsl
    • Mapping
    • Modules
    • Index Modules
    • River
    • Java Api
    • Groovy Api
      • Maven Repository
        • Anatomy
        • Client
        • Count
        • Delete
        • Get
        • Index
        • Search
  • ES Appendix
  • Glossary
PyES Documentation
  • Docs »
  • ES Reference »
  • Groovy Api »
  • Search
  • Edit on GitHub

SearchΒΆ

The search API is very similar to the Java search API. The Groovy extension allows to provide the search source to execute as a Closure including the query itself (similar to GORM criteria builder):

def search = node.client.search {
    indices "test"
    types "type1"
    source {
        query {
            term(test: "value")
        }
    }
}

search.response.hits.each {SearchHit hit ->
    println "Got hit $hit.id from $hit.index/$hit.type"
}

It can also be execute using the “Java API” while still using a closure for the query:

def search = node.client.prepareSearch("test").setQuery({
        term(test: "value")
}).gexecute();

search.response.hits.each {SearchHit hit ->
    println "Got hit $hit.id from $hit.index/$hit.type"
}

The format of the search Closure follows the same JSON syntax as the Search API request.

Next Previous

© Copyright 2010, Alberto Paro and Elastic Search. All Rights Reserved.. Revision d146d7cb.

Built with Sphinx using a theme provided by Read the Docs.