正确的分析仪用于带反斜杠的字段 [英] Correct analyzer for a field with backslash

查看:78
本文介绍了正确的分析仪用于带反斜杠的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试使用Windows凭据字段的正确分析器设置新的索引映射,其格式为 domain \ username .

So, I'm trying to setup a new index mapping with the correct analyzer for a Windows credential field, which has the format domain\username.

我希望能够搜索域,用户名和域\用户名.但是默认的分析器似乎忽略了反斜杠(也就是说,如果我尝试搜索domain \ username,它将搜索"domain OR username"而忽略反斜杠),并且如果我尝试使用空格分析器,则它似乎仅在domain \上匹配用户名.

I want to be able to search for domain, username AND domain\username. But the default analyzer seems to ignore the backslash (meaning, if I try to search for domain\username it will search for "domain OR username" ignoring the backslash), and if I try the whitespace analyzer it seems to only match on domain\username.

有什么提示吗?

推荐答案

您可以使用路径层次标记器,将反斜杠设置为定界符-doc

You could use the path hierarchy tokenizer, setting the backslash as delimiter - doc here Try:

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_path_tree": {
          "tokenizer": "custom_hierarchy"
        },
        "custom_path_tree_reversed": {
          "tokenizer": "custom_hierarchy_reversed"
        }
      },
      "tokenizer": {
        "custom_hierarchy": {
          "type": "path_hierarchy",
          "delimiter": "\"
        },
        "custom_hierarchy_reversed": {
          "type": "path_hierarchy",
          "delimiter": "\",
          "reverse": "true"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "file_path": {
        "type": "text",
        "fields": {
          "tree": {
            "type": "text",
            "analyzer": "custom_path_tree"
          },
          "tree_reversed": {
            "type": "text",
            "analyzer": "custom_path_tree_reversed"
          }
        }
      }
    }
  }
}
POST my_index/_analyze
{
  "analyzer": "custom_path_tree",
  "text": "C:\Windows\Users"
}

这篇关于正确的分析仪用于带反斜杠的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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