painless split

2020-01-05  本文已影响0人  秦汉邮侠

painless 简介

应用

使用手册

image.png

https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-field.html

image.png

https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536

String[] parts = /_/.split(request)

String.split is not available because it compiles a regex. In Painless, regexes are a feature that can be disabled, and also statically compiled (thus the special syntax using the "slashy string" to get a Pattern object above.

实践

POST /daily_quotes/_update_by_query?conflicts=proceed
{
  "script": {
    "source": "String s = ctx._source['tsCode'];String[] array = /\\./.split(s);ctx._source.code_a = array[0];ctx._source.region = array[1]",
    "lang": "painless"
  }
}
image.png
POST /daily_quotes/_update_by_query?conflicts=proceed
{
  "script": {
    "source": "String s = ctx._source['tsCode'];String[] array = / /.split(s);ctx._source.code_a = array[0];ctx._source.region = array[1]",
    "lang": "painless"
  }
}
image.png

如何验证脚本

https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-execute-api.html#_score_context

POST /_scripts/painless/_execute
{
  "script": {
    "source": "String[] array = /\\./.split(params.count); return array.length",
    "params": {
      "count": "123.SH",
      "total": 1000.0
    }
  }
}
上一篇 下一篇

猜你喜欢

热点阅读