elasticsearch 使用仪表板中的时间过滤器更改Kibana中Vega的范围,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega" /> elasticsearch 使用仪表板中的时间过滤器更改Kibana中Vega的范围,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega" />

elasticsearch 使用仪表板中的时间过滤器更改Kibana中Vega的范围

elasticsearch 使用仪表板中的时间过滤器更改Kibana中Vega的范围,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega,我正在使用Kibana7.1 我已经成功地创建了织女星线图。我可以让它显示一个月的数据,但我希望用户可以在仪表板中使用时间过滤器,并允许vega可视化随它改变 我从织女星的文档中读到了这一点 "%context%": true, "%timefield%": "@timestamp" 内部url将解决这个问题,但当我这样做时,它会给我 设置url.body.query时,不得使用url.%context%和url.%timefield% 我的完整elasticsearch代码如下所示:

我正在使用Kibana7.1

我已经成功地创建了织女星线图。我可以让它显示一个月的数据,但我希望用户可以在仪表板中使用时间过滤器,并允许vega可视化随它改变

我从织女星的文档中读到了这一点

  "%context%": true,
  "%timefield%": "@timestamp"
内部url将解决这个问题,但当我这样做时,它会给我 设置url.body.query时,不得使用
url.%context%和url.%timefield%

我的完整elasticsearch代码如下所示:

  "data": {
    "url": {
      "%context%":"true",
      "index": "access_log",
      "body": {
        "query": {
          "bool": {
            "must": [
              {"term": {"request_1": "rent"}},
              {"term": {"status": 200}}
            ]
          }
        },
        "aggs": {
          "histo": {
            "date_histogram": {
              "field": "date",
              "interval": "day"
            },
            "aggs": {
              "start_agg": {
                "filter": {
                  "term": {"request_2": "start"}
                }
              },
              "check_agg": {
                "filter": {
                  "term": {"request_2": "check"}
                }
              },
              "start_check": {
                "bucket_script": {
                  "buckets_path": {
                    "start_count": "start_agg._count",
                    "check_count": "check_agg._count"
                  },
                  "script": "params.start_count / params.check_count"
                }
              }
            }
          }
        }
      }
    },
    "format": {
      "property": "aggregations.histo.buckets"
    }
  },
  "mark": {
    "type":"line"
  },
  "encoding": {
    "x": {
      "field": "key",
      "type": "temporal",
      "axis": {"title": false}
    },
    "y": {
      "field": "start_check.value",
      "type": "quantitative",
      "axis": {"title": "Document count"}
    },
    "tooltip":[
      {"field":"start_check.value", 
       "type" : "quantitative"},
      {"field":"key",
       "type" :"temporal"}
    ]
  }
}
插入
%timefled%:“date”
其中日期是我的一个工作字段。

插入
%timefled%:“date”
其中日期是我的一个工作字段。

引用:

当使用
“%context%”:true
或定义
“%timefield%”的值时
正文不能包含查询。要在VEGA规范中自定义查询(例如,添加一个附加过滤器,或移动时间过滤器),请定义查询并使用占位符,如上例所示。解析后,占位符将替换为仪表板或可视化的实际上下文

他们谈论的“上面的例子”如下:

{
  body: {
    query: {
      bool: {
        must: [
          // This string will be replaced
          // with the auto-generated "MUST" clause
          "%dashboard_context-must_clause%"
          {
            range: {
              // apply timefilter (upper right corner)
              // to the @timestamp variable
              @timestamp: {
                // "%timefilter%" will be replaced with
                // the current values of the time filter
                // (from the upper right corner)
                "%timefilter%": true
                // Only work with %timefilter%
                // Shift current timefilter by 10 units back
                shift: 10
                // week, day (default), hour, minute, second
                unit: minute
              }
            }
          }
        ]
        must_not: [
          // This string will be replaced with
          // the auto-generated "MUST-NOT" clause
          "%dashboard_context-must_not_clause%"
        ]
        filter: [
          // This string will be replaced
          // with the auto-generated "FILTER" clause
          "%dashboard_context-filter_clause%"
        ]
      }
    }
  }
}
而且,正如文件中已经定义的那样:

  • “%dashboard\u context-must\u子句%”
    :字符串被包含筛选器的对象替换
  • “%dashboard\u context-filter\u子句%”
    :字符串被包含筛选器的对象替换
  • “%dashboard\u context-must\u not\u子句%”
    :字符串被包含筛选器的对象替换
因此,如果您想同时使用具有自定义查询的用户定义筛选器或时间筛选器,则必须使用这三个字符串,而不是
“%context%”:true
。它们将由Kibana解析,并由Elasticsearch查询对象替换:一个表示“必须”,一个表示“过滤器”,一个表示“必须”

像这样的简单模式可能很有用:

{
  body: {
    query: {
      bool: {
        must: [
          // {
          //   A "MUST" clause of yours
          // },
          "%dashboard_context-must_clause%"
        ]
        must_not: [
          // {
          //   A "MUST_NOT" clause of yours
          // },
          "%dashboard_context-must_not_clause%"
        ]
        filter: [
          // {
          //   A "FILTER" clause of yours
          // },
          "%dashboard_context-filter_clause%"
        ]
      }
    }
  }
}
如果某些类别中没有任何子句,只需将相应的
%dashboard\u context-XXXXX\u clause%”字符串保留为不带其他对象的字符串,就像第一个示例中的“FILTER”或“MUST\u NOT”一样。

引用:

当使用
“%context%”:true
或定义
“%timefield%”的值时
正文不能包含查询。要在VEGA规范中自定义查询(例如,添加一个附加过滤器,或移动时间过滤器),请定义查询并使用占位符,如上例所示。解析后,占位符将替换为仪表板或可视化的实际上下文

他们谈论的“上面的例子”如下:

{
  body: {
    query: {
      bool: {
        must: [
          // This string will be replaced
          // with the auto-generated "MUST" clause
          "%dashboard_context-must_clause%"
          {
            range: {
              // apply timefilter (upper right corner)
              // to the @timestamp variable
              @timestamp: {
                // "%timefilter%" will be replaced with
                // the current values of the time filter
                // (from the upper right corner)
                "%timefilter%": true
                // Only work with %timefilter%
                // Shift current timefilter by 10 units back
                shift: 10
                // week, day (default), hour, minute, second
                unit: minute
              }
            }
          }
        ]
        must_not: [
          // This string will be replaced with
          // the auto-generated "MUST-NOT" clause
          "%dashboard_context-must_not_clause%"
        ]
        filter: [
          // This string will be replaced
          // with the auto-generated "FILTER" clause
          "%dashboard_context-filter_clause%"
        ]
      }
    }
  }
}
而且,正如文件中已经定义的那样:

  • “%dashboard\u context-must\u子句%”
    :字符串被包含筛选器的对象替换
  • “%dashboard\u context-filter\u子句%”
    :字符串被包含筛选器的对象替换
  • “%dashboard\u context-must\u not\u子句%”
    :字符串被包含筛选器的对象替换
因此,如果您想同时使用具有自定义查询的用户定义筛选器或时间筛选器,则必须使用这三个字符串,而不是
“%context%”:true
。它们将由Kibana解析,并由Elasticsearch查询对象替换:一个表示“必须”,一个表示“过滤器”,一个表示“必须”

像这样的简单模式可能很有用:

{
  body: {
    query: {
      bool: {
        must: [
          // {
          //   A "MUST" clause of yours
          // },
          "%dashboard_context-must_clause%"
        ]
        must_not: [
          // {
          //   A "MUST_NOT" clause of yours
          // },
          "%dashboard_context-must_not_clause%"
        ]
        filter: [
          // {
          //   A "FILTER" clause of yours
          // },
          "%dashboard_context-filter_clause%"
        ]
      }
    }
  }
}

如果某些类别中没有任何子句,只需将相应的
%dashboard\u context-XXXXX\u clause%”字符串保留为不带其他对象的字符串,就像第一个示例中的“FILTER”或“MUST\u NOT”一样。

该字符串中有一个拼写错误。你确定它解决了你的问题吗?无论何时设置时间域,它似乎都会给出错误。该字符串中有一个输入错误。你确定它解决了你的问题吗?无论何时设置timefield,它似乎都会给出错误。