ElasticSearch 路径层次结构 Tokenizer 聚合
ElasticSearch Path Hierarchy Tokenizer Aggregation
我将在此处使用此示例。
我的映射代码如下: 我的映射代码如下: 我的映射代码如下:
PUT file-path-test
{
"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 file-path-test/_doc/1
{
"file_path": "/User/alice/photos/2017/05/16/my_photo1.jpg"
}
POST file-path-test/_doc/2
{
"file_path": "/User/alice/photos/2017/05/16/my_photo2.jpg"
}
POST file-path-test/_doc/3
{
"file_path": "/User/alice/photos/2017/05/16/my_photo3.jpg"
}
POST file-path-test/_doc/4
{
"file_path": "/User/alice/photos/2017/05/15/my_photo1.jpg"
}
POST file-path-test/_doc/5
{
"file_path": "/User/bob/photos/2017/05/16/my_photo1.jpg"
}
下面的查询似乎是空的。
GET / file-path-test / _search
{
"aggs": {
"FILTER": {
"terms": {
"field": "file_path."
}
}
}
}
回复:
"aggregations": {
"FILTER": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
这是什么原因?
你提到的例子很简单,它没有在tokeniser字段映射中添加一些东西...基本上在字段中添加以下内容
"search_analyzer": "keyword",
"fielddata": true
还要确保在整个字段上进行汇总:file_path.tree
或 file_path.tree_reversed
例如
GET /file-path-test/_search
{
"aggs": {
"_doc": {
"terms": {
"field": "file_path.tree"
}
}
}
}
我将在此处使用此示例。
我的映射代码如下: 我的映射代码如下: 我的映射代码如下:
PUT file-path-test
{
"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 file-path-test/_doc/1
{
"file_path": "/User/alice/photos/2017/05/16/my_photo1.jpg"
}
POST file-path-test/_doc/2
{
"file_path": "/User/alice/photos/2017/05/16/my_photo2.jpg"
}
POST file-path-test/_doc/3
{
"file_path": "/User/alice/photos/2017/05/16/my_photo3.jpg"
}
POST file-path-test/_doc/4
{
"file_path": "/User/alice/photos/2017/05/15/my_photo1.jpg"
}
POST file-path-test/_doc/5
{
"file_path": "/User/bob/photos/2017/05/16/my_photo1.jpg"
}
下面的查询似乎是空的。
GET / file-path-test / _search
{
"aggs": {
"FILTER": {
"terms": {
"field": "file_path."
}
}
}
}
回复:
"aggregations": {
"FILTER": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
这是什么原因?
你提到的例子很简单,它没有在tokeniser字段映射中添加一些东西...基本上在字段中添加以下内容
"search_analyzer": "keyword",
"fielddata": true
还要确保在整个字段上进行汇总:file_path.tree
或 file_path.tree_reversed
例如
GET /file-path-test/_search
{
"aggs": {
"_doc": {
"terms": {
"field": "file_path.tree"
}
}
}
}