Elasticsearch - 范围查询工作错误

时间:2018-02-12 11:15:44

标签: elasticsearch range

我使用kibana DEV Tools来查询一些范围数据,但有2次点击超出我的预期,为什么会发生?

image of the range query

查询:

{
    "query" : {
        "constant_score" : { 
            "filter" : {
                "range" : { 
                    "rss" : {
                      "gte": 3000000
                    }
                }
            }
        }
    }
}

结果:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 69,
        "successful": 69,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "BBQ",
                "_type": "BBQ",
                "_id": "AWGJaCYkk-tGbWgj2e6R",
                "_score": 1,
                "_source": {
                    "message": [
                        "nodeProcessInfo"
                    ],
                    "@timestamp": "2018-02-12T09:45:59.525Z",
                    "rss": "92636",
                    "@version": "1",
                    "host": "192.168.213.96"
                }
            },
            {
                "_index": "BBQ",
                "_type": "BBQ",
                "_id": "AWGJaJxzk-tGbWgj2e-V",
                "_score": 1,
                "_source": {
                    "message": [
                        "nodeProcessInfo"
                    ],
                    "@timestamp": "2018-02-12T09:46:29.680Z",
                    "rss": "85272",
                    "@version": "1",
                    "host": "192.168.213.96"
                }
            }
        ]
    }
}

范围查询的结果不符合我的预期,为什么gte => 3000000但rss = 92636出现了吗?

======================编辑于2018.2.13 =========(1) < / p> 像这样的日志:

“nodeProcessInfo | auth-server-1 | auth | 9618 | 1.9 | 1.2 | 98060 | 2018-2-12 6:33:43 PM |”

像这样的过滤器:

filter {
if "nodeProcessInfo" in [message] {  
    mutate {
        split => ["message", "|"]
            add_field => {
                "serverId" => "%{[message[1]]}"
            }
            add_field => {
                "serverType" => "%{[message[2]]}"
            }
            add_field => {
                "pid" => "%{[message[3]]}"
            }
            add_field => {
                "cpuAvg" => "%{[message[4]]}"
            }
            add_field => {
                "memAvg" => "%{[message[5]]}"
            }
            add_field => {
                "rss" => "%{[message[6]]}"
            }
            add_field => {
                "time" => "%{[message[7]]}"
            }
        convert => ["rss", "integer"] # I try convert rss to int, but failed
        add_tag => "nodeProcessInfo"
    }

}

}

======================编辑于2018.2.13 =========(2) < / p>

我让转换代码在一个新的mutate中,并且它使“rss”成为int类型,但是范围查询的结果也错了,更改代码如下:

if "nodeProcessInfo" in [message] {  
        mutate {
            split => ["message", "|"]
                ...
                ...
                add_field => {
                    "rss" => "%{[message[6]]}"
                }
        }
        mutate {
            convert => ["rss", "integer"] # add a new mutate here
        }
    }

======================编辑于2018.2.13 =========(3) < / p>

最后我发现了为什么rss'type被转换为int但是范围查询也错了:

  

“您无法更改现有的映射类型,您需要使用正确的映射创建新索引并再次索引数据。”

所以我创建了一个新的字段名而不是rss,范围查询的结果就是现在。

1 个答案:

答案 0 :(得分:1)

你能分享索引的映射吗?

我认为问题就像我在您分享的搜索结果中看到的那样, rss 字段的类型是文字字符串

如果是这样,那么您正在使用的范围查询将它们视为字符串字符,并根据该字符给出结果。

您尝试使用的是数字范围,如果您使用rss字段的类型将数据编入索引,然后触发相同的查询,则该数字范围将起作用。

然后,您将获得所需的重播