繁体   English   中英

ElasticSearch查询过滤掉某些相机

[英]ElasticSearch Query to filter out certain cameras

我需要创建一个过滤器,它将占用我的所有相机并过滤掉与“蓝图”相关联的相机。 它位于MongoDB中我的相机的属性中。 我想过滤掉没有"BluePrint"类型的相机。

我相信我需要解决的部分是方法getAllCamerasquery部分。

self.evaluateCameras = function() {
    self.getAllCameras(function(err, cameras) {
        if(err) {
            console.log(err);
        }
        else {
            // -- publish newly included cameras
            cameras.forEach(function(camera) {
                if(self.includedCameras[camera._id] == undefined) {
                    camera._source.entityId = camera._id;
                    camera._source.systemType = camera._type;
                    self.publish(camera._source, "create")
                    // -- to scale this need to do caching in Redis shared cache across processes
                    self.includedCameras[camera._id] = camera;
                }
            });
        }

        // process any messages received while initializing stream
        self.initComplete = true;
        for(var j = 0; j < self.tempMessageCache.length; j++) {
            var cacheMsg = self.tempMessageCache[j];
            self.evalPublish(cacheMsg);
        }
        self.tempMessageCache = [];

    });
};

self.getAllCameras = function(callback) {
    self.q = {
        "from": 0,
        "size": 10000, // -- todo: implement some kind of paging
        "sort": [
            {'properties.name': 'asc'},
            {'properties.cameraId': 'asc'}
        ],
        "query": {
            "filtered": {
                "query": {
                    "match_all": {}
                },
                "filter": {
                    "and": [
                        {
                            "exists": {"field": "properties.geoRef"}
                        },
                        {
                            "geo_shape": {
                                "properties.geoRef": {
                                    "shape": {
                                        "coordinates": properties.geoRef.coordinates,
                                        "type": "point"
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    };
    elasticClient.search({
        index: 'myproject-now',
        type: 'system.camera',
        body: self.q
    }, function (err, response) {
        if (err)
            callback(err, null);
        else {
            callback(null, response.hits.hits);
        }
    });
};

经过对弹性搜索的一些研究,这是我提出的解决方案:

self.getAllCameras = function(callback) {
    self.q = {
        "from": 0,
        "size": 10000, // -- todo: implement some kind of paging
        "sort": [
            {'properties.name': 'asc'},
            {'properties.cameraId': 'asc'}
        ],
        "query": {
            "filtered": {
                "query": {
                    "match_all": {}
                },
                "filter": {
                    "and": [
                        {
                            "exists": {"field": "properties.geoRef"}
                        },
                        {
                            "not": {
                                "term": {
                                    "properties.geoRef.type" : "floorplan"
                                }
                            }
                        }
                    ]
                }
            }
        }
    };
    elasticClient.search({
        index: 'myproject-now',
        type: 'system.camera',
        body: self.q
    }, function (err, response) {
        if (err)
            callback(err, null);
        else {
            callback(null, response.hits.hits);
        }
    });
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM