1

I try to evaluate a web-application for my masterthesis. For this I want to make a user study, where I prepare the data in elasitc found, and send my web application to the testers. As far as I know, elastic found does not allow dynamic scripting for security reasons. I try to refomulate the following dynamic script query:

GET my_index/document/_search
{
  "query": {
    "match_all":{}
  },
  "aggs": {
    "stadt": {
      "sum": {
        "script": "_index['textBody']['frankfurt'].tf()"
      }
    }
  }  
}

This query sums up all term frequencies in the document field textBody for the term frankfurt.

In order to reformulate the query without dynamic scripting, I've taken a look on groovy scripts without dynamic scripting, but I still get parsing errors.

My approach to this was:

GET my_index/document/_search
{
  "query": {
    "match_all":{}
  },
  "aggs": {
    "stadt": {
      "sum": {
        "script": {
            "script_id": "termFrequency",
            "lang" : "groovy",
            "params": {
              "term" : "frankfurt"
            }
        }        
      }
    }
  }  
}

and the file termFrequency.groovy in the scripts directory:

_index['textBody'][term].tf()

I get the following parsing error:

Parse Failure [Unexpected token START_OBJECT in [stadt].]
1
  • What version of ES you are using? Commented Nov 28, 2015 at 14:39

1 Answer 1

1

This is the correct syntax assuming your file is inside config/scripts directory.

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "stadt": {
      "sum": {
        "script_file": "termFrequency",
        "lang": "groovy",
        "params": {
          "term": "frankfurt"
        }
      }
    }
  },
  "size": 0
}

Also the term should be variable rather than string so it should be

_index['textBody'][term].tf()

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.