[英]Kibana scripted fields sort
I've faced the following issue:我遇到了以下问题:
I've created a script field which returns String type field我创建了一个返回字符串类型字段的脚本字段
But when I try to make sorting on this field by the Kibana means there's an error但是当我尝试通过 Kibana 对该字段进行排序时,意味着出现错误
"Error loading data [script_exception] compile error"
“加载数据时出错 [script_exception] 编译错误”
Then I went to the discover tab, selected this field, clicked to sort by this field: discover然后我转到发现选项卡,选择此字段,单击按此字段排序:发现
After the error, I opened the Inspect menu item and looked at the request that is being sent: inspect出现错误后,我打开了 Inspect 菜单项并查看了正在发送的请求: inspect
I saw the request, which was leaded to elastic:我看到了请求,这导致了弹性:
{
"version": true,
"size": 500,
"sort": [
{
"event_date": {
"order": "desc",
"unmapped_type": "boolean"
}
},
{
"_script": {
"script": {
"source": "if (doc.containsKey('message.keyword')) {\n//if (doc['message.keyword'].size() == 0) return 'field not found';\ndef path = doc['message.keyword'].value;\nString[] message = /\\n/.split(path);\nString param = 'IP = ';\n for (int i = 0; i < message.length; i++) {\n int index = message[i].indexOf(param);\n if (index > -1) {\n return message[i].substring(index+param.length());\n // return 'ее';\n }\n }\nreturn '';\n} else return '';",
"lang": "painless"
},
"type": "number",
"order": "asc"
}
}
],
.........
}
And I've found out that Kibana gives this field "type": "number"而且我发现 Kibana 给出了这个字段 "type": "number"
If i send the request directly to elastic, by changing "type": "number"
, to "type": "string"
Then the request is running.如果我将请求直接发送到弹性,通过将
"type": "number"
更改为"type": "string"
然后请求正在运行。
Could you please, explain, what's the problem?你能解释一下,有什么问题吗?
full error:完整错误:
Error: Bad Request
at Fetch._callee3$ (<url>/bundles/commons.bundle.js:3:3997981)
at l (<url>/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970406)
at Generator._invoke (<url>/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970159)
at Generator.forEach.e.<computed> [as next] (<url>/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970763)
at asyncGeneratorStep (<url>/bundles/commons.bundle.js:3:3991504)
at _next <url>/bundles/commons.bundle.js:3:3991815)
and chome console i see response:和 chome 控制台我看到响应:
{
"statusCode": 400,
"error": "Bad Request",
"message": "[script_exception] compile error",
"attributes": {
"error": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... return message[i].substring(index+param.le ...",
" ^---- HERE"
],
"script": "if (doc.containsKey('message.keyword')) {\n//if (doc['message.keyword'].size() == 0) return 'field not found';\ndef path = doc['message.keyword'].value;\nString[] message = /\\n/.split(path);\nString param = 'IP = ';\n for (int i = 0; i < message.length; i++) {\n int index = message[i].indexOf(param);\n if (index > -1) {\n return message[i].substring(index+param.length());\n // return 'ее';\n }\n }\nreturn '';\n} else return '';",
"lang": "painless",
"position": {
"offset": 358,
"start": 333,
"end": 383
},
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot cast from [java.lang.String] to [double]."
}
}
}
}
The provided error snippet is insufficient to say exactly what went wrong.提供的错误片段不足以准确说明出了什么问题。
Beautifying your script gives美化你的脚本给
if (doc.containsKey('message.keyword')) {
def path = doc['message.keyword'].value;
String[] message = /\\n/.split(path);
String param = 'IP = ';
for (int i = 0; i < message.length; i++) {
int index = message[i].indexOf(param);
if (index > -1) {
return message[i].substring(index + param.length());
}
}
return '';
} else {
return ''
}
and in all of these instances, a string
would be returned.在所有这些情况下,都会返回一个
string
。 So ES will throw an exception if your script sort is of type number
but you've provided strings.因此,如果您的脚本类型是
number
类型但您提供了字符串,则 ES 将抛出异常。
Lastly, what do you mean by I saw the request, which was leaded to elastic
?最后,
I saw the request, which was leaded to elastic
是什么意思? How did this request come about?这个要求是怎么来的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.