# Odd query help?

**URL:** <https://discuss.elastic.co/t/odd-query-help/377586>\
**Category:** Elasticsearch\
**Created:** [April 28, 2025, 5:05pm UTC](https://discuss.elastic.co/t/odd-query-help/377586 "2025-04-28T17:05:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisR](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@ChrisR](https://discuss.elastic.co/u/ChrisR)\
**Post date:** [April 28, 2025, 5:05pm UTC](https://discuss.elastic.co/t/odd-query-help/377586/1 "2025-04-28T17:05:29Z")

</div>

Is there a way to query for docs that contain one and only one keyword value?

For example, supposing these docs:

```json
{"id": 1, "keywd": ["A"]}
{"id": 2, "keywd": ["B"]}
{"id": 3, "keywd": ["A", "B"]}

```

Is there a way to query for docs keywd = A and has no other values, so that only doc 1 would return and not doc 3?

---

<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:** [April 28, 2025, 7:01pm UTC](https://discuss.elastic.co/t/odd-query-help/377586/2 "2025-04-28T19:01:42Z")

</div>

One way would be by storing the length of the array in addition to the values.  
If you search for `A`, then the size of the array must be `1`.

Using a bool query with those 2 clauses would work I think.

---

<div class="post-metadata">

**Author:** ![ChrisR](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@ChrisR](https://discuss.elastic.co/u/ChrisR)\
**Post date:** [April 28, 2025, 7:23pm UTC](https://discuss.elastic.co/t/odd-query-help/377586/3 "2025-04-28T19:23:20Z")

</div>

That was exactly the solution, thank you!
