ES不区分大小写的布尔字段 [英] ES case insensitive boolean field

查看:116
本文介绍了ES不区分大小写的布尔字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1m条记录,其中一列是布尔值.它包含三个值. FALSE,TRUE,[空白] .

I have 1m record where one column is boolean. It contains three values. FALSE, TRUE, [Blank].

我希望将此字段视为布尔值.由于这种情况,它不被视为布尔值.我知道ES支持布尔值true或"true",并且对此没有分析器.

I want this field to be treated as boolean. Due to the case, it is not treated as boolean. I understand that ES supports true or "true" as boolean and no analyser on this.

还有其他方法可以处理我的记录吗?记录也是动态的.当负载到达时,必须适当地存储它.

Is there any other way to handle my records? Records are dynamic too. As load arrives, it has to be stored appropriately.

推荐答案

是的,有一种方法可以使用

Yes, there's a way to achieve this using an ingest pipeline that transforms your field.

您可以使用 <代码>转换处理器,如下所示.当转换为布尔值时,转换处理器将忽略大小写,因此"TRUE" 将转换为true.与"FALSE" 相同.添加 ignore_missing:true 以忽略空值:

You can create an ingest pipeline with a convert processor like below. When converting to boolean, the convert processor ignores the casing, so "TRUE" will be converted to true. Same for "FALSE". Add ignore_missing: true to ignore null values:

PUT _ingest/pipeline/bool-pipeline
{
  "description": "converts FALSE/TRUE to boolean",
  "processors" : [
    {
      "convert" : {
        "field" : "bool",
        "type": "boolean",
        "ignore_missing": true
      }
    }
  ]
}

然后,当您为文档建立索引时,只需在查询中指定管道,文档就会在被索引之前流过 bool-pipeline .

Then when you index your documents, you can just specify the pipeline in the query and the documents will flow through the bool-pipeline before being indexed.

PUT index/_doc/123?pipeline=bool-pipeline
{
    "bool": "TRUE"
}

PUT index/_doc/456?pipeline=bool-pipeline
{
    "bool": "FALSE"
}

PUT index/_doc/789?pipeline=bool-pipeline
{
    "bool": null
}

这篇关于ES不区分大小写的布尔字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆