gpt4 book ai didi

javascript - ElasticSearch 查询过滤掉某些摄像头

转载 作者:行者123 更新时间:2023-11-28 05:32:10 26 4
gpt4 key购买 nike

我需要创建一个过滤器,该过滤器将采用我的所有相机并过滤掉与“蓝图”关联的相机。它位于 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);
}
});
};

最佳答案

经过对elasticsearch的一些研究,这是我想出的解决方案:

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);
}
});
};

关于javascript - ElasticSearch 查询过滤掉某些摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com