Агрегация токенизатора иерархии путей ElasticSearch - PullRequest
1 голос
/ 08 апреля 2020

Я собираюсь использовать этот пример здесь.

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pathhierarchy-tokenizer-examples.html#analysis -pathhierarchy-tokenizer-examples

Мой код отображения приведен ниже: Код моего отображения ниже: Код моего отображения ниже:

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": []
     }
   }

В чем причина?

1 Ответ

0 голосов
/ 09 апреля 2020

Пример, который вы упомянули, довольно прост и не добавляет некоторых вещей в отображение поля токенизатора ... В основном добавьте следующее к полю

          "search_analyzer": "keyword",
          "fielddata": true

, также обязательно агрегируйте по полному полю : file_path.tree или file_path.tree_reversed

Например.

GET /file-path-test/_search
{
   "aggs": {
     "_doc": {
       "terms": {
         "field": "file_path.tree"
       }
     }
   }
}
...