contact@yottabyte.cn
400-085-0159
调查问卷
J

API

分组操作

terms:按字段值分组

按指定的field的值对数据分组,可为数值型和非数值型。

定义:

"field": // String: 字段名
"size": // Integer: 可选,返回结果数量,默认10。当为0的时候size=inter.MAX_VALUE。
"order": { // 可选,默认"_count:desc"
  // 可使用以下值
  "_count": "desc" // 事件数多到少
  "_count": "asc" // 事件数少到多
  "_term": "desc" // 字段值字符倒序
  "_term": "asc" // 字段值字符正序
  // 更多值:可使用group内的stats操作的结果,如group内有名为nested_stats的stats操作则可用: "nested_stats.avg": "asc"
}
"buckets": [
  {
    "key":, // 根据field不同为不同类型:该组的字段值
    "doc_count": // Integer:时间段内的事件数
  },
  // 更多数组元素
]

样例:

{
  "query": {
    "split_method": {
      "terms": {
        "field": "apache.method",
        "size": 5
    }
  }
}
{
  "result": true,
  "total": 100
  "data": {
    "split_method": {
      "buckets": [
        {
          "key": "GET",
          "doc_count": 50
        },
        {
          "key": "POST",
          "doc_count": 50
        }
      ]
    }
  }
}

timeline:按指定时间间隔分组

按指定的时间间隔对数据进行分组。

定义:

"period": // String:符合正则(\d+)(year|month|week|day|hour|minute|second|millis)指定分段或者default自动分段
"buckets": [
    {
      "key": // String:用于识别的key
      "from": // Integer:unix时间戳
      "to": // Integer:unix时间戳
      "doc_count": // Integer:时间段内的事件数
    },
    // 更多数组元素
  ]

样例:

{
  "query": {
    "timeline_one_day_result": {
      "timeline": {
        "period": "1day"
      }
    }
  }
}
{
  "result": true,
  "total": 100
  "data": {
    "timeline_one_day_result": {
      "buckets": [
        {
          "key": "1.422288E12-1.4223744E12",
          "from": 1422288000000,
          "to": 1422374400000,
          "doc_count": 50
        },
        {
          "key": "1.4223744E12-1.4224608E12",
          "from": 1422374400000,
          "to": 1422460800000,
          "doc_count": 50
        }
      ]
    }
  }
}

range:数值型字段按指定区间分组

按照字段的值的范围对数据分组,只用于数值型字段。

定义:

"field": // String: 指定字段名
"ranges": {
  // from和to至少填写一个
  "from": // Integer:大于等于
  "to": // Integer:小于
}
"buckets": [
  {
    "key":, // Number:该组的字段值
    "doc_count": // Integer:事件数
  },
  // 更多数组元素
]

样例:

{
  "query": {
    "status_range_result": {
      "range": {
        "field": "apache.status",
        "ranges": [
          {
              "to": 200
          },
          {
              "from": 200,
              "to": 300
          },
          {
              "from": 300,
              "to": 400
          },
          {
              "from": 400,
              "to": 500
          },
          {
              "from": 500
          }
        ]
      }
    }
  }
}
{
  "result": true,
  "total": 100
  "data": {
    "status_range_result": {
      "buckets": [
        {
          "key": "*-200.0",
          "to": 200,
          "doc_count": 0
        },
        {
          "key": "200.0-300.0",
          "from": 200,
          "to": 300,
          "doc_count": 6967
        },
        {
          "key": "300.0-400.0",
          "from": 300,
          "to": 400,
          "doc_count": 1355
        },
        {
          "key": "400.0-500.0",
          "from": 400,
          "to": 500,
          "doc_count": 134
        },
        {
          "key": "500.0-*",
          "from": 500,
          "doc_count": 26
        }
      ]
    }
  }
}

histogram:数值型字段按指定步长间隔分组

按照指定的步长划分数据集,只用于数值型字段。

定义:

"field": // String:字段名
"interval": // String:步长
"buckets": {
  {
    "key": // Number:每段区间的起点值,表示此段是>=key到<(key+interval)的区间
    "doc_count": // Integer:分组内数量统计值
  },
  // 注,如果某段区间无值,则对应的元素不在数组中。
}

样例:

{
  "query": {
    "histogram_result": {
      "histogram": {
        "field": "apache.status",
          "interval": 1
      }
    }
  }
}
{
  "result": true,
  "total": 8831,
  "data": {
    "histogram_result": {
      "buckets": [
      {
        "key": 200,
        "doc_count": 7194
      },
      {
        "key": 301,
        "doc_count": 30
      },
      {
        "key": 302,
        "doc_count": 29
      },
      {
        "key": 304,
        "doc_count": 1404
      },
      {
        "key": 404,
        "doc_count": 7
      },
      {
        "key": 499,
        "doc_count": 140
      },
      {
        "key": 500,
        "doc_count": 24
      },
      {
        "key": 504,
        "doc_count": 3
      }
      ]
    }
  }
}