# Query "at least one not in given array"

**URL:** <https://discuss.elastic.co/t/query-at-least-one-not-in-given-array/316984>\
**Category:** Elasticsearch\
**Created:** [October 19, 2022, 10:29am UTC](https://discuss.elastic.co/t/query-at-least-one-not-in-given-array/316984 "2022-10-19T10:29:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ltr31](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltr31/32/112261_2.png) [@ltr31](https://discuss.elastic.co/u/ltr31)\
**Post date:** [October 19, 2022, 10:29am UTC](https://discuss.elastic.co/t/query-at-least-one-not-in-given-array/316984/1 "2022-10-19T10:29:21Z")

</div>

Hello

I have documents with let say positive terms and negative terms like

```auto
{
   ...
   "mood" : [
        "happy",
        "excited",
        "furious"
   ],
   ...
}

```

Positive terms can be an infinite list of values, while negative terms are among 3 only :

- furious
- livid
- scared

**Now** , I want to query documents that have positive terms even if they contain a negative term. What I _don't want_ is a document which contains only negative moods. Documents all contain at least one mood.

Documents OK :

```auto
{ ... "mood" : ["happy", "honest", "joyful"] ... }
{ ... "mood" : ["fabulous", "livid", "scared"] ... }

```

Documents not OK :

```auto
{ ... "mood" : ["livid"] ... }
{ ... "mood" : ["scared", "furious"] ... }

```

Remember that I cannot give an exhaustive list of positive terms expected, the list is infinite. Which is finite is the negative mood list.

I have tried many writings of queries but none gave me satisfaction.

Do you have any ideas how I can achieve this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 19, 2022, 11:20am UTC](https://discuss.elastic.co/t/query-at-least-one-not-in-given-array/316984/2 "2022-10-19T11:20:52Z")

</div>

It sounds to me like this is something that is known at the time the document is indexed or updated, so the most efficient way would probably be to add a `positive_mood_flag` field to the document and set this to true or false.

You can probably also determine this flag through a runtime field, but indexing it would scale and perform better.

---

<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:** [November 16, 2022, 11:21am UTC](https://discuss.elastic.co/t/query-at-least-one-not-in-given-array/316984/3 "2022-11-16T11:21:26Z")

</div>

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