[英]ElasticSearch Query to filter out certain cameras
我需要創建一個過濾器,它將占用我的所有相機並過濾掉與“藍圖”相關聯的相機。 它位於MongoDB中我的相機的屬性中。 我想過濾掉沒有"BluePrint"
類型的相機。
我相信我需要解決的部分是方法getAllCameras
的query
部分。
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.