限制Elasticsearch中的字段长度值



我有一个Elasticsearch集群,它包含许多带有单个字段及其值的数据。我有一个字段名Description,它有一个小段落作为值。不同字段的值长度不同。我想限制这些字段的值。我试过以下方法。

  • 我用自定义映射创建了一个索引
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 150
}
}
}
  • 索引数据字段值映射显示它们在150中,但我的描述值与以前相同
  • 我还尝试使用
PUT index_name/_settings
{
"index.mapping.field_name_length.limit": 150
} 

但这些都没有奏效。我的描述数据仍然和以前一样。那么我该怎么办呢?我应该在上传到集群时限制我的描述值,还是在上传后限制弹性搜索集群的值?
我的主要任务是将描述数据的最大长度设置为150个字符。提前谢谢。

您添加的配置不会修改您发送的_source文档,只会修改被索引的文档。

您有两个选项可以缩短给定字段的值:

A。在将源文档发送到Elasticsearch 之前修改源文档

B。让你的文档通过一个接收管道,它将为你做这件事:

PUT _ingest/pipeline/shorten-description
{
"description": "Shorten my description field",
"processors": [
{
"script": {
"if": "ctx.description != null",
"lang": "painless",
"source": "ctx.description = ctx.description.substring(0, params.length)",
"params": {
"length": 150
}
}
}
]
}

然后,您可以使用摄取管道对文档进行索引:

PUT my-index/_doc/1?pipeline=shorten-description
{
"description": "...."
}

最新更新