1

我有一个索引,网址,如下所示:

path: {
   type: "string"
},
@timestamp: {
   type: "date",
   format: "strict_date_optional_time||epoch_millis"
},

该路径将存储来自 url 的 PATH 部分,例如:

https://facebook.com/profile/photos/album/1

将存储为:

/profile/photos/album/1

我正在存储各种路径,所以可能更像:

/profile/photos/album/1
/profile/photos/album/2
/profile/photos/album/2
/profile/photos/album/2
/profile/friends/1
/profile/friends/2
/newsfeed/me/
/newsfeed/me/
/newsfeed/friendName/

我正在尝试找出每个路径具有的唯一网页浏览量。我不确定我应该怎么做,我应该使用正则表达式吗?

我想它看起来像(伪代码):

{
    "query": {
      "regexp": {
            "path": "" 
        },
        "unique": true
    }
}
4

1 回答 1

0

所以我发现了如何做到这一点。我正在使用该aggs方法并使用正则表达式来排除结果!

{
  "size": 0, // Don't return any _source results
  "aggs": {
    "path": { // This is the field that I'm 
      "terms": {
        "field": "path",
        "exclude": ".*(media|cache).*" // Add in the values here seper
      }
    }
  }
}

分解:

  1. 小路
    • 只是聚合的标签
  2. 字段(路径)
    • 我要在其上运行以下正则表达式的字段
  3. 排除
    • 不要返回路径中有媒体或缓存的文档

我从Elasticsearch 中发现了这一点:Run aggregation on field & filter out specific values using a regexp not matching values

于 2016-09-28T03:43:11.293 回答