[英]ElasticSearch/Kibana: how to aggregate similar type of pages
全新的 kibana 用戶,我正在嘗試跟蹤我網站上的使用情況。
我在以下類型的 url 中有一些頁面:
https://example.com/services/{serviceId}/users
所以每個服務的 serviceId 都會發生變化,但是我想看看有多少人去他們服務的/users
頁面。
有沒有辦法匯總那個計數?
假設 url 是多字段類型,您有以下映射:
PUT my_url_index
{
"mappings" : {
"properties" : {
"url" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
POST my_url_index/_doc/1
{
"url": "https://example.com/services/101/users"
}
POST my_url_index/_doc/2
{
"url": "https://example.com/services/asdasd/users"
}
POST my_url_index/_doc/3
{
"url": "https://example.com/services/555/users"
}
POST my_url_index/_doc/4
{
"url": "https://example.com/users/4444/create"
}
請注意,我假設您只有 URL 的一種變體,其中包含services
和user
令牌。
下面的查詢應該可以幫助您獲得總計數以及每個用戶去過多少次的計數:
POST my_url_index/_search
{
"size": 0,
"query": {
"query_string": {
"query": "(services) AND (users)",
"fields": ["url"]
}
},
"aggs": {
"my_users": {
"terms": { <----- Note the logic mentioned here
"script": {
"source": "doc['url.keyword'].toString().substring(30, doc['url.keyword'].toString().indexOf('/users'));"
},
"size": 10
}
}
}
}
{
"took" : 336,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3, <---- total count
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : { <----- count of each user
"my_users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "101",
"doc_count" : 1
},
{
"key" : "555",
"doc_count" : 1
},
{
"key" : "asdasd",
"doc_count" : 1
}
]
}
}
}
讓我知道這是否有幫助以及您是否正在尋找其他任何東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.