# Document-level Permissions Approach

**URL:** https://discuss.elastic.co/t/document-level-permissions-approach/8384
**Category:** Elasticsearch
**Created:** [July 11, 2012, 2:58pm UTC](https://discuss.elastic.co/t/document-level-permissions-approach/8384 "2012-07-11T14:58:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jori\_2](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jori\_2](https://discuss.elastic.co/u/Jori_2)
#### Post date: [July 11, 2012, 2:58pm UTC](https://discuss.elastic.co/t/document-level-permissions-approach/8384/1 "2012-07-11T14:58:01Z")

</div>

Hi,

I have a question about how to implement the following in ElasticSearch:

1. _Tokens_ can be a _User IDs_, _Organization IDs_, and _Group IDs_.  
(To make this example easier to follow I am using single-character tokens  
but in reality they are 16-character long strings that are the  
Base64-encoding of 12-byte MongoDB IDs. There is also a unique Public ID  
which all public documents have and which all queries can access.)
2. Each _user_ has access to a list of _tokens_ they are authorized to  
access.
3. Each _document_ has a list of _tokens_ that are authorized to access  
it.

I tried to do something like the following:

_SAMPLE DOCUMENT_

{  
content: "Some sample text",  
auth: ["A", "C", "D"]  
}

_SAMPLE QUERY_

{  
"query": {  
"filtered": {  
"query": {  
"query\_string": { "query": "sample" }  
},  
"filter": {  
"terms": { "auth": ["A", "B"] }  
}  
}  
}  
}

This query is not working for me. I am trying to use _terms_ to basically  
to do an array/array intersection test but it seems like it can only do a  
single-value/array intersection test since the example works if I replace:

auth: ["A", "C", "D"]

with

auth: "A"

Is there a way to make terms work with this or should I be taking a  
different approach?

Thank you!

p.s. Thanks for/to ElasticSearch and its community.

---

<div class="post-metadata">

### Author: ![Hendrik](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hendrik](https://discuss.elastic.co/u/Hendrik)
#### Post date: [November 20, 2013, 9:16am UTC](https://discuss.elastic.co/t/document-level-permissions-approach/8384/2 "2013-11-20T09:16:01Z")

</div>

Maybe this is interesting  
[https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/tavroa3Nw5g](https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/tavroa3Nw5g)

Am Mittwoch, 11. Juli 2012 16:58:01 UTC+2 schrieb Jori:

> Hi,
> 
> I have a question about how to implement the following in Elasticsearch:
> 
> 1. _Tokens_ can be a _User IDs_, _Organization IDs_, and _Group IDs_.  
> (To make this example easier to follow I am using single-character tokens  
> but in reality they are 16-character long strings that are the  
> Base64-encoding of 12-byte MongoDB IDs. There is also a unique Public ID  
> which all public documents have and which all queries can access.)
> 2. Each _user_ has access to a list of _tokens_ they are authorized to  
> access.
> 3. Each _document_ has a list of _tokens_ that are authorized to  
> access it.
> 
> I tried to do something like the following:
> 
> _SAMPLE DOCUMENT_
> 
> {  
> content: "Some sample text",  
> auth: ["A", "C", "D"]  
> }
> 
> _SAMPLE QUERY_
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": { "query": "sample" }  
> },  
> "filter": {  
> "terms": { "auth": ["A", "B"] }  
> }  
> }  
> }  
> }
> 
> This query is not working for me. I am trying to use _terms_ to  
> basically to do an array/array intersection test but it seems like it can  
> only do a single-value/array intersection test since the example works if I  
> replace:
> 
> auth: ["A", "C", "D"]
> 
> with
> 
> auth: "A"
> 
> Is there a way to make terms work with this or should I be taking a  
> different approach?
> 
> Thank you!
> 
> p.s. Thanks for/to Elasticsearch and its community.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 2:06am UTC](https://discuss.elastic.co/t/document-level-permissions-approach/8384/3 "2017-07-06T02:06:04Z")

</div>


