弹性搜索中的聚合查询拦截

弹性搜索中的聚合查询拦截,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我现在正在调查弹性搜索,我想了解某些事情的可能性。如有任何建议,将不胜感激 我试图解决一个非常具体的用例,如下所示: 在弹性搜索中进行聚合之前,我想对每一行运行授权检查?可能吗 这就像调用外部api来查看用户是否有权对特定行进行聚合,如果有,则应将其添加到聚合结果集中 示例: 比方说,我在弹性搜索中有一些文档数据,每个文档都附加了一个特定的标记。我在另一个关系数据库中有一些用户数据,模式如下(userId,tag) 当user1查询标签“es”上的文档数量时,它应该返回2,而对于user2,它应

我现在正在调查弹性搜索,我想了解某些事情的可能性。如有任何建议,将不胜感激

我试图解决一个非常具体的用例,如下所示:

在弹性搜索中进行聚合之前,我想对每一行运行授权检查?可能吗

这就像调用外部api来查看用户是否有权对特定行进行聚合,如果有,则应将其添加到聚合结果集中

示例:

比方说,我在弹性搜索中有一些文档数据,每个文档都附加了一个特定的标记。我在另一个关系数据库中有一些用户数据,模式如下(userId,tag)

当user1查询标签“es”上的文档数量时,它应该返回2,而对于user2,它应该返回0,因为用户没有附加“es”标签

这就像在增加计数之前拦截每个对聚合的调用以进行一些定制检查。基本上,我希望将搜索结果限制为基于用户的内容

弹性搜索中的模式和查询

PUT /document
{
    "mappings": {
        "post": {
            "properties": {
                "document_id": {
                    "type":"integer"
                },
                "tag": {
                    "type":"string",
                    "index":"not_analyzed"
                },
                "document_name": {
                    "type":"string"
                }
            }
        }
    }
}


POST document/reports 
{
    "document_id":123,
    "tag":"es",
    "document_name":"elastic search indexing"
}

POST document/reports 
{
    "document_id":1233,
    "tag":"es",
    "document_name":"elastic search routing"
}


POST document/reports 
{
    "document_id":1234,
    "tag":"kafka",
    "document_name":"kafka partitioning"
}
关系数据库中的表结构

userId | tag            |
-------------------------
 user1 | es             |
 user2 | kafka          |
{
   "took": 4,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "types": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "es",
               "doc_count": 2
            }
         ]
      }
   }
}
搜索请求查询

GET document/reports/_search
{
    "query": {
        "match": {
            "_all": "es"
        }
    },
    "size": 0,
    "aggs": {
        "types": {
            "terms": {
                "field":"tag"
            }
        }
    }
}
样本响应

userId | tag            |
-------------------------
 user1 | es             |
 user2 | kafka          |
{
   "took": 4,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "types": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "es",
               "doc_count": 2
            }
         ]
      }
   }
}

你能用一个例子来说明你的用例吗?谢谢你的回复,我已经添加了一个例子。希望你明白我在做什么。如果不清楚,请告诉我。好的,是否可以在您的文档中添加另一个
user
字段,以便您可以轻松地表达这两个条件,即
user=user1
tag=es
?不,不可能。用户数据由完全独立的应用程序/系统维护。只有通过api,我们才能获得用户的数据。既然您控制SQL数据库,为什么不包括基于进行查询的用户的约束?因此,如果user1发出请求,查询将类似于
select count(*),tag from reports WHERE tag IN('es')group by tag