elasticsearch - 用于类似于拆分的带状疱疹的 Elasticsearch 处理器?
问题描述
有没有可以做带状疱疹的处理器,或者我可以以某种方式定制一个?
在下面的管道处理器中,我拆分了空格字符,但我也想组合单词,比如 shingle 分析器会:
PUT _ingest/pipeline/split
{
"processors": [
{
"split": {
"field": "title",
"target_field": "title_suggest.input",
"separator": "\\s+"
}
}
]
}
例子:
“高级业务开发人员”需要包含这些术语的建议字段。
- 高级业务开发人员
- 企业发展者
- 开发商
以下是启发这个问题的文章和答案的链接:
解决方案
这是我使用自定义脚本提出的一种解决方案:
PUT _ingest/pipeline/shingle
{
"description" : "Create basic shingles from title field and input in another field title_suggest",
"processors" : [
{
"script": {
"lang": "painless",
"source": """
String[] split(String s, char d) {
int count = 0;
for (char c : s.toCharArray()) {
if (c == d) {
++count;
}
}
if (count == 0) {
return new String[] {s};
}
String[] r = new String[count + 1];
int i0 = 0, i1 = 0;
count = 0;
for (char c : s.toCharArray()) {
if (c == d) {
r[count++] = s.substring(i0, i1);
i0 = i1 + 1;
}
++i1;
}
r[count] = s.substring(i0, i1);
return r;
}
if (!ctx.containsKey('title')) { return; }
def title_words = split(ctx['title'], (char)' ');
def title_suggest = [];
for (def i = 0; i < title_words.length; i++) {
def shingle = title_words[i];
title_suggest.add(shingle);
for (def j = i + 1; j < title_words.length; j++) {
shingle = shingle + ' ' + title_words[j];
title_suggest.add(shingle);
}
}
ctx['title_suggest'] = title_suggest;
"""
}
}
]
}
推荐阅读
- javascript - 如果另一个 h2 选择关闭当前一个,我如何一次显示一个 h2?
- c - 大约堆栈位置
- perl - Perl:谁能告诉我如何解决这个警告
- javascript - 我在javascript的回调函数中做错了什么?
- mongodb - 如何在 MongoDB 3.4 中加入多个集合?
- json - 我有一个 twitch vod 的纯文本聊天记录,是否可以将此文件转换为 json 格式?
- azure - terraform 在配置 azure vm 时激活趋势微代理
- svn - 如何在centos中编写svn shell脚本
- r - R studio how to solve a naming substitution error
- linux - systemd如何接收poweroff信号?