elasticsearch - 正确的分析仪用于带反斜杠的字段

标签 elasticsearch elasticsearch-analyzers

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

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

有小费吗?

最佳答案

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

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"
}

关于elasticsearch - 正确的分析仪用于带反斜杠的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60924725/

相关文章:

elasticsearch - 如何将子文档添加到 ElasticSearch 索引

elasticsearch - 在多层汇总中返回具有空字段的文档

java - ElasticSearch 高级 API 使用自定义设置创建索引返回错误

Elasticsearch : Completion suggester not working with whitespace Analyzer

java - Magnolia 6.1.1 分析器(小写字母和重音符号)

elasticsearch - 如何在 Elasticsearch 中为精确搜索提供比语音搜索更高的分数?

php - 文档缺少异常Elasticsearch PHP

groovy - 使用脚本有条件地更新 Elasticsearch 中的文档

elasticsearch - 应用分析器/过滤器时搜索elasticsearch错误

elasticsearch - 用于动态定义正则表达式搜索的 Elastic Search Analyzer