- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试根据群集字段以及podName字段是否具有值进行过滤。
然后,我想过滤掉某些具有特定值的字段,但获得除指定的群集字段以外的其他值。
因此,以下查询还将返回cluster2和cluster3的值。
我不知道什么是正确的语法。
{
"size":50,
"query":{
"bool":{
"must":[
{
"range":{
"timestamp":{
"gte":"now-1h"
}
}
},
{
"query_string":{
"query":"(podstatus.podName:* AND cluster:cluster1) AND NOT podstatus.containerStatus:true AND NOT podstatus.phase:Running AND NOT podstatus.phase:Succeeded AND NOT podstatus.started: true"
}
}
]
}
}
}
样本文件
{
"timestamp": "2020-07-09T17:30:04",
"cluster": "cluster1",
"namespace": "kube-system",
"podstatus.podName": "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus": "false",
"podstatus.restartCount": 0,
"podstatus.started": "false",
"podstatus.phase": "Succeeded"
}
制图
{
"cluster-resources-cluster1-2020.07.08-000001" : {
"mappings" : {
"properties" : {
"allocated" : {
"properties" : {
"pods-percent" : {
"type" : "float"
}
}
},
"capacity" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"mem" : {
"type" : "long"
},
"pods" : {
"type" : "long"
}
}
},
"cluster" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"depstatus" : {
"properties" : {
"availableReplicas" : {
"type" : "long"
},
"deploymentName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"readyReplicas" : {
"type" : "long"
},
"replicas" : {
"type" : "long"
},
"unavailableReplicas" : {
"type" : "long"
},
"updatedReplicas" : {
"type" : "long"
}
}
},
"namespace" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podstatus" : {
"properties" : {
"containerStatus" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"phase" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"restartCount" : {
"type" : "long"
},
"started" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"requests" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"cpu-percent" : {
"type" : "float"
},
"mem" : {
"type" : "long"
},
"mem-percent" : {
"type" : "float"
},
"pods" : {
"type" : "long"
}
}
},
"timestamp" : {
"type" : "date"
}
}
}
}
}
最佳答案
您的查询似乎工作正常。但是,我将发布以下步骤,如果您能以类似方式找到任何观察结果,请告诉我。
我已经完成了映射,创建了示例文档,您共享的查询以及得到的响应。
对应:
PUT cluster_index_001
{
"mappings" : {
"properties" : {
"allocated" : {
"properties" : {
"pods-percent" : {
"type" : "float"
}
}
},
"capacity" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"mem" : {
"type" : "long"
},
"pods" : {
"type" : "long"
}
}
},
"cluster" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"depstatus" : {
"properties" : {
"availableReplicas" : {
"type" : "long"
},
"deploymentName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"readyReplicas" : {
"type" : "long"
},
"replicas" : {
"type" : "long"
},
"unavailableReplicas" : {
"type" : "long"
},
"updatedReplicas" : {
"type" : "long"
}
}
},
"namespace" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podstatus" : {
"properties" : {
"containerStatus" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"phase" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"restartCount" : {
"type" : "long"
},
"started" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"requests" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"cpu-percent" : {
"type" : "float"
},
"mem" : {
"type" : "long"
},
"mem-percent" : {
"type" : "float"
},
"pods" : {
"type" : "long"
}
}
},
"timestamp" : {
"type" : "date"
}
}
}
}
样本文件:
POST cluster_index_001/_doc/1
{
"timestamp": "2020-07-09T17:30:04",
"cluster": "cluster1",
"namespace": "kube-system",
"podstatus.podName": "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus": "false",
"podstatus.restartCount": 0,
"podstatus.started": "false",
"podstatus.phase": "Failed"
}
POST cluster_index_001/_doc/2
{
"timestamp": "2020-07-10T17:30:04",
"cluster": "cluster1",
"namespace": "kube-system",
"podstatus.podName": "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus": "false",
"podstatus.restartCount": 0,
"podstatus.started": "false",
"podstatus.phase": "Failed"
}
POST cluster_index_001/_doc/3
{
"timestamp": "2020-07-10T17:30:04",
"cluster": "cluster2",
"namespace": "kube-system",
"podstatus.podName": "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus": "false",
"podstatus.restartCount": 0,
"podstatus.started": "false",
"podstatus.phase": "Failed"
}
查询样例:
POST cluster_index_001/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "now-2d"
}
}
},
{
"query_string": {
"query":"(podstatus.podName:* AND cluster:cluster1) AND NOT podstatus.containerStatus:true AND NOT podstatus.phase:Running AND NOT podstatus.phase:Succeeded AND NOT podstatus.started:true"
}
}
]
}
}
}
您也可以像上面的
cluster.keyword
一样使用上面的
cluster.keyword:cluster1
进行精确匹配。
{
"took" : 86,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.4700036,
"hits" : [
{
"_index" : "cluster_index_001",
"_type" : "_doc",
"_id" : "1",
"_score" : 2.4700036,
"_source" : {
"timestamp" : "2020-07-09T17:30:04",
"cluster" : "cluster1",
"namespace" : "kube-system",
"podstatus.podName" : "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus" : "false",
"podstatus.restartCount" : 0,
"podstatus.started" : "false",
"podstatus.phase" : "Failed"
}
},
{
"_index" : "cluster_index_001",
"_type" : "_doc",
"_id" : "2",
"_score" : 2.4700036,
"_source" : {
"timestamp" : "2020-07-10T17:30:04",
"cluster" : "cluster1",
"namespace" : "kube-system",
"podstatus.podName" : "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus" : "false",
"podstatus.restartCount" : 0,
"podstatus.started" : "false",
"podstatus.phase" : "Failed"
}
}
]
}
}
请注意查询正常工作并返回正确的文档集
GET cluster_index_001/_explain/3 <----- Note this
{
"query": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "now-2d"
}
}
},
{
"query_string": {
"query":"podstatus.podName:* AND cluster:cluster1 AND NOT podstatus.containerStatus:true AND NOT podstatus.phase:Running AND NOT podstatus.started: true"
}
}
]
}
}
}
我看到的响应如下:
{
"_index" : "cluster_index_001",
"_type" : "_doc",
"_id" : "3",
"matched" : false,
"explanation" : {
"value" : 0.0,
"description" : "Failure to meet condition(s) of required/prohibited clause(s)",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(DocValuesFieldExistsQuery [field=timestamp])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "no match on required clause (+ConstantScore(NormsFieldExistsQuery [field=podstatus.podName]) +cluster:cluster1 -podstatus.containerStatus:true -podstatus.phase:running -podstatus.started:true)",
"details" : [
{
"value" : 0.0,
"description" : "Failure to meet condition(s) of required/prohibited clause(s)",
"details" : [
{
"value" : 1.0,
"description" : "ConstantScore(NormsFieldExistsQuery [field=podstatus.podName])",
"details" : [ ]
},
{
"value" : 0.0,
"description" : "no match on required clause (cluster:cluster1)",
"details" : [
{
"value" : 0.0,
"description" : "no matching term",
"details" : [ ]
}
]
}
]
}
]
}
]
}
}
请注意,以上响应中的描述如何清楚地说明这一点:
"description" : "Failure to meet condition(s) of required/prohibited clause(s)"
另请注意以下几点:
"description" : "no match on required clause (+ConstantScore(NormsFieldExistsQuery [field=podstatus.podName]) +cluster:cluster1 -podstatus.containerStatus:true -podstatus.phase:running -podstatus.started:true)",
结果,您现在知道了为什么文档3没有返回响应。
"cluster": "cluster2, cluster1"
http://<your_host_name>:<port>/cluster-resources-cluster1-2020.07.08-000001/_settings
,然后观察是否有针对以下目的实现的自定义分析器: Edge Ngrams或Ngrams,以及您的standard
分析器是否已被覆盖。 http://<your_host_name>:<port>/cluster-resources-cluster1-2020.07.08-000001/_stats?pretty
,并注意是否发现任何奇怪的东西。 关于json - 弹性query_string返回不需要的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62819546/
我确定这已经被问过无数次了,但我无法让它发挥作用, 我正在尝试用查询字符串重写一个 url,我的 url 是例如: http://example.com/articles/index.php?keyw
如果我要创建这样的查询: "query": { "query_string": { "query": "User:mjohnst", "default_field": "Text"
我在ES 5中具有以下映射的索引 { "test-log": { "mappings": { "record": { "properties": {
我的数据库与 Elasticsearch 同步,以优化我们的搜索结果并更快地请求。 我在查询用户时遇到问题,我想通过查询来查找我的用户,它可以是姓名、电话、IP、... 我的实际查询是 query_s
这是我的测试: 使用比赛 {“query”:{“bool”:{“must”:[{“match”:{“name”:{“query”:“ka”}}}},{“term”:{“kind”:“k1 “}}]}}
我在ElasticSearch(我正在使用1.6版)应用程序中有以下查询: { "query":{ "span_multi":{ "match":{
我正在尝试在 Elasticsearch 中使用日期数学进行日期范围查询,但它没有返回任何结果: `query: { bool: { must: { q
我有一个页面显示我的数据库中的数据。在用户看到数据之前,他们有几个选择框,因此他们可以选择以多种不同方式过滤数据,例如选择显示特定时间段内的数据。当我使用 get 方法时,url 看起来类似于下面的内
我有一个包含 field 视频的索引,其值为 1.flv。如果我执行以下查询: "query": { "query_string": { "query": "2.flv"
我正在使用 ElasticSearch (2.4) 和官方 Python 客户端执行简单查询。我的代码: from elasticsearch import Elasticsearch es_clie
当我将表单数据发布到我的服务器时,我的 fastcgi 应用程序能够从 nginx 读取除 QUERY_STRING 之外的所有参数。查看 CONTENT_LENGTH 给出了正确的字符串长度,我的浏
关于 SO 的第一个问题! 我在 apache 2.2.22 上运行 PHP 5.3.10。我只是这样做: Apache 的 error.log 中的输出如下: Array ( [HTTP_
我有一个关于 .htaccess 和 QUERY_STRING 的问题。 我尝试使用我的 htaccess 重定向一个 URL,如下所示: http://mydomain.tld/out/http%3
您好,我有一个奇怪的问题:我的任务是将 WP 页面 (page_id=2) 重定向到同一域上的页面 (about),但是当我使用字符串重定向时: RewriteEngine On RewriteCon
我在这里遇到一个奇怪的问题。我正在将一个(工作)站点移动到一个我无法直接访问的新 apache 服务器(我必须通过两个人才能完成工作)。 该站点使用名为 adframe 的 perl 脚本来解析 ht
假设我有一个索引,并使用以下语句添加了一些文档: POST test/item/_bulk {"id": 1, "text": "one two"} {"id": 2, "text": "one tw
在我的Elasticsearch中,我有一个像这样的文档: "field_4" : [ "ip_address", "127.0.0
我需要的是,elastic 应该在 中搜索多个字段并按字段优先级返回数据。 例如:对于搜索字符串 obil hon , elastic 应该在 fields[title, description, m
我试图得到一个大于 X 且字段等于 Y 的结果。我试过这个: { "sort": { "datapublicacao": "desc" }, "query": {
我想从 query_string 中读取数据。 例如: username=kramsp&password=overfloww123 我想从查询字符串中读取值 query= username=[data
我是一名优秀的程序员,十分优秀!