Search code examples
elasticsearchquerydsl

Search query with two different fields in elasticsearch


I need to search in elasticsearch like

select * from tablename where file.content='xyz' and filePermission.Id='abc'  

What query I need to add. Is it possible to give a filter to search query? I have set file.content as a default field.


Solution

  • AND SQL queries can be written as a "must bool query":

    {
        "query" : {
            "bool" : {
                "must" : [
                    { "match" : { "file.content":"xyz"} },
                    { "match" : { "filePermission.Id" : "abc"} }
                ]
            }
        }
    }