小编rem*_*ram的帖子

Elasticsearch - 使用路径层次结构标记生成器来访问不同级别的类别

我是Elasticsearch的新手,对路径的分层标记化器有疑问.这是我的代码示例:

我的映射代码:

PUT /my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "path-analyzer": {
          "type": "custom",
          "tokenizer": "path-tokenizer"
        }
      },
      "tokenizer": {
        "path-tokenizer": {
          "type": "path_hierarchy",
          "delimiter": "."
        }
      }
    }
  },
  "mappings": {
    "my_type": {
      "dynamic": "strict",
      "properties": {
        "group_path": {
          "type": "string",
          "index_analyzer": "path-analyzer",
          "search_analyzer": "keyword"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的PUT:

PUT /my_index/my_type/1
{
  "group_path": ["Book.Thriller.Adult","DVD.Comedy.Kids"]
}
Run Code Online (Sandbox Code Playgroud)

这是我的查询:

GET /my_index/my_type/_search?search_type=count
{
   "aggs": {
      "category": {
         "terms": {
            "field": "group_path",
            "size": 0
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

{
   ... …
Run Code Online (Sandbox Code Playgroud)

path hierarchy categories elasticsearch

14
推荐指数
1
解决办法
7693
查看次数

标签 统计

categories ×1

elasticsearch ×1

hierarchy ×1

path ×1