Elasticsearch Viewtool

Last Updated: Aug 20, 2021
documentation for the dotCMS Content Management System

The Elasticsearch viewtool allows a Widget to perform an Elasticsearch query (using full Elasticsearch JSON syntax) and return a list of results which you can iterate over using Velocity. Elasticsearch queries can be tested in the Elasticsearch Portlet before using them with the viewtool.

The following example shows how the Elasticsearch Viewtool is mapped in the toolbox.xml file:


In the following example, an Elasticsearch query is supplied to the $estool.search viewtool method to search every Content title containing the word “gas” in the dotCMS content store. The query also prevents matches of any non-English versions of the content, using the “must_not” range for any languageid greater than 1.

#set($results = $estool.search('{
    "query": {
        "bool": {
            "must": {
                "term": {
                    "title": "gas"
            "must_not": {
                "range": {
                    "languageid": {
                        "from": 2,
                        "to": 20

#foreach($con in $results)


For more examples of Elasticsearch queries, please see the Elasticsearch API documentation.

On this page


We Dig Feedback

Selected excerpt: