我尝试为我的硕士学位评估一个Web应用程序。为此,我想进行用户研究,准备在elasitc中准备的数据,然后将我的Web应用程序发送给测试人员。据我所知,出于安全原因, flex 发现不允许动态脚本编写。我尝试重新格式化以下动态脚本查询:
GET my_index/document/_search
{
"query": {
"match_all":{}
},
"aggs": {
"stadt": {
"sum": {
"script": "_index['textBody']['frankfurt'].tf()"
}
}
}
}
该查询求和单词
textBody
的文档字段frankfurt
中的所有单词频率。为了在不使用动态脚本的情况下重新构造查询,我研究了groovy scripts without dynamic scripting,但仍然遇到解析错误。
我的解决方法是:
GET my_index/document/_search
{
"query": {
"match_all":{}
},
"aggs": {
"stadt": {
"sum": {
"script": {
"script_id": "termFrequency",
"lang" : "groovy",
"params": {
"term" : "frankfurt"
}
}
}
}
}
}
以及
termFrequency.groovy
目录中的文件scripts
:_index['textBody'][term].tf()
我收到以下解析错误:
Parse Failure [Unexpected token START_OBJECT in [stadt].]
最佳答案
假设您的文件位于config/scripts
目录中,则这是正确的语法。
{
"query": {
"match_all": {}
},
"aggs": {
"stadt": {
"sum": {
"script_file": "termFrequency",
"lang": "groovy",
"params": {
"term": "frankfurt"
}
}
}
},
"size": 0
}
另外,术语应该是
variable
而不是string
,因此应该是_index['textBody'][term].tf()
希望这可以帮助!
关于elasticsearch - 无需动态脚本的术语频率总和脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33956217/