# Can we filter document in nested object with user.metadata jobs?

**URL:** https://discuss.elastic.co/t/can-we-filter-document-in-nested-object-with-user-metadata-jobs/185876
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [June 14, 2019, 2:30pm UTC](https://discuss.elastic.co/t/can-we-filter-document-in-nested-object-with-user-metadata-jobs/185876 "2019-06-14T14:30:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jonathan\_Dee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_dee/32/47716_2.png) [@jonathan\_Dee](https://discuss.elastic.co/u/jonathan_Dee)
#### Post date: [June 14, 2019, 2:30pm UTC](https://discuss.elastic.co/t/can-we-filter-document-in-nested-object-with-user-metadata-jobs/185876/1 "2019-06-14T14:30:57Z")

</div>

Hello,  
I'm new on Elastic solutions and i'm actually testing x-pack.

I am searching to filter what can see users in an Elasticsearch index, futhermore I want to filter some document into a nested object.

I will explain a short scenario: We got two users: Alice and Bob Alice work on X and Bob work on Y We got document about Movies : Example: name : Matrix date : 1999 actors : [Keanu Reeves, Laurence Fishburne]

Now I want to filter what can see Alice and Bob in the actors field. By example Keanu Reeves can be seen by who work on X and Laurence Fishburne can be seen by who work on Y.

To do this I am tring to use X-Pack security properties but I have some problems and maybe you will help me.

There is my Index mapping :

```
{"settings": {
        "index": {
            "number_of_replicas": 0,
            "number_of_shards": 1
        }
    },
    "mappings": {
            "properties": {
                "security_attributes": {
                    "properties": {
            "level": {"type":"short"},
                        "jobs": {"type":"keyword"},
                        "min_jobs": {"type":"short"}
                    }
                },
        "name":{"type":"text"},
                "date":{"type":"text"},
        "actors":{"type":"nested", 
                "properties":{
                    "security_attributes":{
                        "properties":{
                            "level": {"type":"short"},
                                        "jobs": {"type":"keyword"},
                                        "min_jobs": {"type":"short"}
                            }
                        },
                    "name":{ "type": "string"}
                    }
                }
             }
        }
    }'

```

And I try to grant a query template at user roles.

```
{"template":
    {"source":"
        {"bool":
             {"filter":
                 [{"range": 
                    {"security_attributes.level": 
                        {"lte": "{{_user.metadata.level}}"}}},
                {"terms_set":{"security_attributes.jobs": 
                    {"terms":{{#toJson}}_user.metadata.jobs{{toJson}},
                    "minimum_should_match_field": "security_attributes.min_jobs"}}}]}}"}
}

```

To filter document by roles or jobs that work know I want to filter inside the nested object by jobs but I don't know how I can add this filter to the previous template.

Someone have an idea ?

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [June 17, 2019, 1:03am UTC](https://discuss.elastic.co/t/can-we-filter-document-in-nested-object-with-user-metadata-jobs/185876/2 "2019-06-17T01:03:23Z")

</div>

I'm afraid this is not possible.

You can control which fields are visible to which users, and you can control which documents are visible to each user, but you cannot filter a field.

---

<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 15, 2019, 1:03am UTC](https://discuss.elastic.co/t/can-we-filter-document-in-nested-object-with-user-metadata-jobs/185876/3 "2019-07-15T01:03:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
