I am investigating elastic search now and I like to get some insights on the possibility of certain things. Any suggestions would be greatly appreciated.
I'm trying to tackle a very specific use case as follows:
I want to run a entitlement check on each row before doing the aggregation in elastic search? Is that possible?
It's like calling an external api to see whether the user has permission to do aggregation on a particular row, If yes, then it should be added to the aggregation resultset.
Example:
Lets say, I have some document data in elastic search, and each document has a specific tag attached. And I have some user data in another relation database with the below schema (userId, tag)
When user1 query elastic for the number of documents on the tag "es" it should return 2 whereas for user2 it should return 0 as the user don't have "es" tag attached.
It's like intercepting each and every call to the aggregation to do some customised check before increasing the count. Basically I'm looking to limit search results to things based on the user.
Schema and queries in elastic search
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"
}
Table structure in relation database
userId | tag |
-------------------------
user1 | es |
user2 | kafka |
Search request query
GET document/reports/_search
{
"query": {
"match": {
"_all": "es"
}
},
"size": 0,
"aggs": {
"types": {
"terms": {
"field":"tag"
}
}
}
}
Sample Response
{
"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
}
]
}
}
}