我的弹性查询中出错 - 范围返回错误的请求

Error in my elasticquery - Range returns bad request

本文关键字:返回 范围 错误 请求 出错 查询 我的      更新时间:2023-09-26

我有以下函数可以进行弹性搜索:

$scope.getLocationHistory = function(device, lastTime){
    console.log("Device location searching");
    query = {
        "query": {
            "bool": {          
                "must": [
                    { "term": {"deviceId":device} },
                    { "match": {"eventType":"Connected"} } 
                ],
                "must_not":[
                    {"query_string": {
                            "query": "Pong",
                            "fields": ["data.message"]
                        }
                    },
                ] 
            }                  
        },
        "range" : {
            "timestamp" : {
                "gt" : "now-1h"
            }
        },
        "filter" : {
            "exists" : { "field" : "data.location" }
        },
        "sort": [{ "timestamp": { "order": "desc" }}]
    }
    $http.post(databaseLocation+"/canary/_search", query).success(function(data, status, headers, config){
        $scope.getMapHistory(data.hits.hits); //Auxiliary function
    }).error(function(data, status, headers, config){
        console.log(data);
    }); 
}

我是弹性查询的新手,我在范围字段上收到此错误:

POST http://... 400 (Bad Request) Object {error: "SearchPhaseExecutionException[Failed to execute ph…arse Failure [No parser for element [range]]]; }]", status: 400}error: "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;....

可能我写错了范围字段,但我发现了如何在此文档中使用它:www.elasticsearch.org/...

我想知道我在查询上做错了什么。

已编辑我只需要向范围添加另一个过滤器就可以工作了,但是如果您将范围作为必须参数,性能会更好

    query = {
        "query": {
            "bool": {          
                "must": [
                    { "range" : { "timestamp" : { "gt" : timeRange }}},
                    { "term": {"deviceId":device} },
                    { "match": {"eventType":"Connected"} } 
                ],
                "must_not":[{
                        "query_string": {
                            "query": "Pong",
                            "fields": ["data.message"]
                        }
                    },
                ] 
            },
        },
        "filter": { 
            "exists" : { "field":"data.location" }
        },
        "sort": [{ "timestamp": { "order": "desc" }}]
    }