# Get documents with certain search criteria and with max priority

**URL:** <https://discuss.elastic.co/t/get-documents-with-certain-search-criteria-and-with-max-priority/119080>\
**Category:** Elasticsearch\
**Created:** [February 8, 2018, 3:37pm UTC](https://discuss.elastic.co/t/get-documents-with-certain-search-criteria-and-with-max-priority/119080 "2018-02-08T15:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESCoder](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ESCoder](https://discuss.elastic.co/u/ESCoder)\
**Post date:** [February 8, 2018, 3:37pm UTC](https://discuss.elastic.co/t/get-documents-with-certain-search-criteria-and-with-max-priority/119080/1 "2018-02-08T15:37:26Z")

</div>

Hi,

I have documents which have two lists, allow and deny, each entry in those lists are \<id, priority\> tuples. For example a document can have the following tuples on it

allow : \<10, 1\>, \<20, 5\>, \<30, 3\>, \<40, 6\>, \<50, 4\>  
deny: \<30, 4\>, \<70, 2\>, \<40, 3\>

When I search for id 40 it should check both the lists, since it exists in both then I would check their priority. Since allow priority is 6 the search should return the document.

When I search for id 30, since it exists on both then I compare priority and since the deny priority is 4 it should not return the document.

How do I translate the above into an elastic search query?

Thanks!

---

<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:** [March 8, 2018, 3:37pm UTC](https://discuss.elastic.co/t/get-documents-with-certain-search-criteria-and-with-max-priority/119080/2 "2018-03-08T15:37:40Z")

</div>

Closed on March 8, 2018, 3:37pm UTC

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