0

ES offers the possibility to store your script within an internal index ( see IndexedScript ), but unfortunately I cannot access it from aggreagtions.

Creating the index:

POST /_scripts/groovy/termFrequency
{
  "script": "_index['textBody'][term].tf()"
}

Using the script within aggreagtions:

GET /my_index/_search
{
   "query":{
      "match_all": {}
   },
   "aggs":{
      "tf_sum":{
        "sum":{
          "script": {
            "script": "termFrequency",
            "lang": "groovy",
            "params": {"term":"keyword"}
          }
        }
      }
   }
}

results in the syntax-error: Parse Failure [Unexpected token START_OBJECT in [tf_sum].

The purpose of the script is, to extract the term frequencies. I don't want to use script_files, because uploading such files is expensive in cloud services (e.g. found).

1
  • What version of ES you are using? Commented Dec 22, 2015 at 15:08

1 Answer 1

1

This is the correct syntax for ES 1.7, you were looking at ES 2.1

GET /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "tf_sum": {
      "sum": {
        "script_id": "termFrequency", <--- you access it with script_id
        "lang": "groovy",
        "params": {
          "term": "keyword"
        }
      }
    }
  },
  "size": 0
}

Hope this helps!

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

1 Comment

thank you, i got confused with different versions of ES.

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.