# Entity Object Security with Elastic Search

**URL:** https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732
**Category:** Elasticsearch
**Created:** [December 5, 2013, 6:49pm UTC](https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732 "2013-12-05T18:49:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Charles\_Gardiner](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@Charles\_Gardiner](https://discuss.elastic.co/u/Charles_Gardiner)
#### Post date: [December 5, 2013, 6:49pm UTC](https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732/1 "2013-12-05T18:49:28Z")

</div>

Howdy yall,

Has anyone here had to deal with entity object security with Elastic  
Search?

What I mean by "entity object security" is that the entity the Document  
represents is not readable by everyone who may be searching the Elastic  
Search database. It would be nice if there was a way that Elastic Search  
had some notion of document security or is this something I would have to  
build into the document representing the entity.

Here is a more specific scenario:

I perform a query against Elastic Search for a specific page and size. I  
get the results and translate the results into domain objects. I then  
check if the user who is about to see these results has the ability to see  
each domain object and if not remove it. The problem with this solution is  
that it removes results from the page after the query and could result in a  
page with no results. Is there a way to integrate user level security into  
Elastic Search?

I realize this question is somewhat broad. Any suggestions are appreciated.  
Thanks  
Charles

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2ec71eba-7451-4c34-9b69-7e4357d3adb7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2ec71eba-7451-4c34-9b69-7e4357d3adb7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [December 5, 2013, 7:02pm UTC](https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732/2 "2013-12-05T19:02:41Z")

</div>

Add a security field or object in your json source doc, for ex:  
{  
"groupid":"sales",  
// your content  
}

Then add a filter to filter your docs by groupid.

You can also define filtered aliases to simplify your search requests.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 déc. 2013 à 19:49, Charles Gardiner [charles@sourceclear.com](mailto:charles@sourceclear.com) a écrit :

Howdy yall,

Has anyone here had to deal with entity object security with Elastic Search?

What I mean by "entity object security" is that the entity the Document represents is not readable by everyone who may be searching the Elastic Search database. It would be nice if there was a way that Elastic Search had some notion of document security or is this something I would have to build into the document representing the entity.

Here is a more specific scenario:

I perform a query against Elastic Search for a specific page and size. I get the results and translate the results into domain objects. I then check if the user who is about to see these results has the ability to see each domain object and if not remove it. The problem with this solution is that it removes results from the page after the query and could result in a page with no results. Is there a way to integrate user level security into Elastic Search?

I realize this question is somewhat broad. Any suggestions are appreciated.  
Thanks  
Charles

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2ec71eba-7451-4c34-9b69-7e4357d3adb7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2ec71eba-7451-4c34-9b69-7e4357d3adb7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ED94EFEB-B04C-479C-9B26-49835AF9E9F9%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/ED94EFEB-B04C-479C-9B26-49835AF9E9F9%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)
#### Post date: [December 6, 2013, 9:41am UTC](https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732/3 "2013-12-06T09:41:44Z")

</div>

I am using Spring Security with their ACL schema for having permissions for  
entity objects.

So I added following mapping to those entities in ES:

"acl": {  
"type": "nested",  
"properties": {  
"id": {  
"type": "integer"  
},  
"permissions": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"owner": {  
"type": "object",  
"properties": {  
"id": {  
"type": "integer"  
},  
"sid": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"name": {  
"type": "multi\_field",  
"fields": {  
"name": {  
"type": "string"  
},  
"partial": {  
"type": "string",  
"index\_analyzer": "my\_ngram"  
}  
}  
}  
}  
}

an entry could look like this:

{  
"owner": {  
"id":1,  
"sid":"ROLE\_ADMIN",  
"name":"Admin"  
}  
"acl": [  
{  
"id":1,  
"permissions": ["READ"]  
},  
{  
"id": 2,  
"permissions" : ["READ","WRITE","ADMIN"]  
}  
]  
}

This way you can easily use an ACL filter to filter the entities:

{  
"filter": {  
"nested" : {  
"filter" : {  
"bool" : {

```
       "must" : [ 
         {
           "terms" : {
             "acl.id" : ["1", "2"]
           }
         }, 
         {
           "terms" : {
             "acl.permissions" : ["read"]
           }
         }
        ]
      }
    },

      "path" : "acl"
 }

```

}

On Thursday, December 5, 2013 7:49:28 PM UTC+1, Charles Gardiner wrote:

Howdy yall,

> Has anyone here had to deal with entity object security with Elastic  
> Search?
> 
> What I mean by "entity object security" is that the entity the Document  
> represents is not readable by everyone who may be searching the Elastic  
> Search database. It would be nice if there was a way that Elastic Search  
> had some notion of document security or is this something I would have to  
> build into the document representing the entity.
> 
> Here is a more specific scenario:
> 
> I perform a query against Elastic Search for a specific page and size. I  
> get the results and translate the results into domain objects. I then  
> check if the user who is about to see these results has the ability to see  
> each domain object and if not remove it. The problem with this solution is  
> that it removes results from the page after the query and could result in a  
> page with no results. Is there a way to integrate user level security into  
> Elastic Search?
> 
> I realize this question is somewhat broad. Any suggestions are  
> appreciated.  
> Thanks  
> Charles

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/64075f8b-a796-422b-bd67-e4e3604a0177%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/64075f8b-a796-422b-bd67-e4e3604a0177%40googlegroups.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:02am UTC](https://discuss.elastic.co/t/entity-object-security-with-elastic-search/14732/4 "2017-07-06T02:02:52Z")

</div>


