我试图在我的查询中使用脚本字段.我启用了沙盒脚本,并尝试使用表达式来计算新字段.
问题是我收到以下错误:
{
"type": "expression_script_compilation_exception",
"reason": "Only the member variable [value] or member methods may be accessed on a field when not accessing the field directly"
}
Run Code Online (Sandbox Code Playgroud)
似乎只有"价值"可以获得.我在这里想念的是什么?
运行以下查询时:
{
"query": {
"match_all": {}
},
"script_fields" : {
"field1" : {
"script" : {
"lang": "expression",
"inline": "doc['about.hobbies'].empty"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
制图:
{
"my_index": {
"mappings": {
"type": {
"properties": {
"about": {
"properties": {
"hobbies": {
"type": "string",
"analyzer": "lowercase"
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小解释:我有一个字段,可以包含字符串值列表.
"hobbies": ["a","b",c"]
Run Code Online (Sandbox Code Playgroud)
它也可以是空的.我希望有一个类型为boolean的脚本字段,当列表不为空时,其值为true;如果列表为空,则为false.
更新:阅读更多内容,我在lucene表达式脚本上遇到了这个文档
相对于其他脚本语言存在一些限制:
- 只能访问数字字段
- 存储的字段不可用
- 如果字段是稀疏的(只有一些文档包含值),则缺少该字段的文档的值为0
我的字段是String类型,可能是问题?如果是,是否有其他方法可以使用基于字符串字段的脚本字段?也许使用groovy?
我认为问题在于该字段是一个嵌套对象,如果我正确阅读文档,那么 doc[\'field\'] 仅支持简单的术语字段。
\n\n\n\n\n但请注意,doc[...] 表示法仅允许简单的值字段(can\xe2\x80\x99t 从中返回 json 对象),并且仅对非分析或基于单个术语的字段有意义。
\n
但是使用 _source 对我有用
\n\n "script_fields" : {\n "field1" : {\n "script" : "_source.about.hobbies.size() > 0"\n }\n },\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
652 次 |
| 最近记录: |