# Granted documents query

**URL:** <https://discuss.elastic.co/t/granted-documents-query/274053>\
**Category:** Kibana\
**Tags:** elastic-stack-security\
**Created:** [May 26, 2021, 12:03pm UTC](https://discuss.elastic.co/t/granted-documents-query/274053 "2021-05-26T12:03:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mar-ro](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mar-ro](https://discuss.elastic.co/u/mar-ro)\
**Post date:** [May 26, 2021, 12:03pm UTC](https://discuss.elastic.co/t/granted-documents-query/274053/1 "2021-05-26T12:03:10Z")

</div>

Hello!  
How can I specify in a granted documents query that I want show only the documents that match with a service.name AND service.environment?  
I tried with the following query but I also saw other service.environment different from the one I indicated (staging):

```auto
{
  "bool": {
    "must": [ // (I also tried with "filter")
      {
        "match": {
          "service.name":"myWeb"
        }
      },
      {
        "match": {
          "service.environment":"staging"
        }
      }
    ]
  }
}

```

Thank you !

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [May 26, 2021, 1:33pm UTC](https://discuss.elastic.co/t/granted-documents-query/274053/2 "2021-05-26T13:33:49Z")

</div>

Hi @mar-ro

Perhaps take a look at this similar post [here](https://discuss.elastic.co/t/api-key-and-document-level-security-query-not-limiting-response/271786/4)

In short I suspect you should be using a `term` query with fields that are of type `keyword`.

The example in the post about uses an API key but the concept is the same.

And using a filter is good approach as well.

---

<div class="post-metadata">

**Author:** ![mar-ro](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mar-ro](https://discuss.elastic.co/u/mar-ro)\
**Post date:** [May 26, 2021, 2:41pm UTC](https://discuss.elastic.co/t/granted-documents-query/274053/3 "2021-05-26T14:41:53Z")

</div>

Ok, thank you @stephenb !  
I'll take a look it !

---

<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:** [June 23, 2021, 2:41pm UTC](https://discuss.elastic.co/t/granted-documents-query/274053/4 "2021-06-23T14:41:59Z")

</div>

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