【问题标题】:Elasticsearch custom separators for the standard analyzer标准分析器的 Elasticsearch 自定义分隔符
【发布时间】:2020-05-26 20:19:35
【问题描述】:

是否可以为standard 分析器提供自定义分隔符列表?

我的应用程序提供了一个元素下拉列表,我可以在其中选择dog,cat,mouse 并将此值用作搜索过滤器。我希望能够选择狗、猫或鼠标作为过滤器值。请注意,逗号不是此元素字段的唯一分隔符。我也可以有dog&catdog<br>catdog;cat;mouse

字段映射:

"mappings": {
    "properties": {
        "element": {
            "type": "text",
        }
        ................
    }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-mapping


    【解决方案1】:

    您可以使用char_filter,它可以将特定字符替换为其他字符,elasticsearch 已经在, & 上中断,对于其他字符(不是分隔符),您可以在 char_filter 中定义它们。

    您还可以使用如下所示的分析 API 来查看 char_filter 是否正确替换了您的分隔符。

    由于<br>是一个HTML代码,标准分析器会为其创建一个token,你可以使用html_strip char_filter,如下所示:

    {
      "tokenizer" : "standard",
      "filter" : ["lowercase"],
      "char_filter" : ["html_strip"],
      "text" : "dog<br>cat"
    }
    
    
    {
        "tokens": [
            {
                "token": "dog",
                "start_offset": 0,
                "end_offset": 3,
                "type": "<ALPHANUM>",
                "position": 0
            },
            {
                "token": "cat",
                "start_offset": 7,
                "end_offset": 10,
                "type": "<ALPHANUM>",
                "position": 1
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      • 2014-10-05
      • 1970-01-01
      相关资源
      最近更新 更多