I need to create a filter that will take all of my cameras and filter out cameras that are associated with 'blueprints'. This is located within the properties of my cameras in MongoDB. I want to filter out cameras that don't have type "BluePrint"
.
I believe the section I need to fix is the query
section in the method getAllCameras
.
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);
}
});
};
After some research into elasticsearch this is the solution I came up with:
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);
}
});
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.