Search code examples
grailsfilterelasticsearchnested

Multiple ElasticSearch filters in Grails


I have the following query in Grails (Plugin elasticsearch:0.0.3.8) which works perfect:

class MyDomain {

 User user
 String text
 Boolean deleted
 Boolean disabled

 static searchable = { user component:true }

}

class User {
    String name
    static searchable = { root false }
}

MyDomain.search(searchType: 'dfs_query_and_fetch') {
        query_string(query: params.query, fields:['text'])
    } {
        nested {
            path = "user"
            query {
                bool {
                    must { match("user.name": params.name) }
                }
            }
        }
    }

But now I wanna add some additional filters : match("deleted": true) match("disabled": true)

Can somebody explain to me how to achieve this? Thanks


Solution

  • I finally figured it out. Many thanks to cfrick for his help.

    MyDomain.search(searchType: 'dfs_query_and_fetch') {
            query_string(query: params.query, fields:['text'])
        } {
            bool {
                must { term(disabled: true) }
                must { term(deleted: true) }
                must {
                    nested {
                        path = "user"
                        query {
                            bool {
                                must { match("user.name": params.name) }
                            }
                        }
                    }
                }
            }
        }