# Match only arrays having one element

**URL:** <https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777>\
**Category:** Elasticsearch\
**Created:** [November 21, 2012, 2:21pm UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777 "2012-11-21T14:21:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Nikolaev](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@Eugene\_Nikolaev](https://discuss.elastic.co/u/Eugene_Nikolaev)\
**Post date:** [November 21, 2012, 2:21pm UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777/1 "2012-11-21T14:21:19Z")

</div>

Hi! I have a 'not-analyzed' field where some categories are stored. Say,  
category: ['a', 'b', 'c']. I need filter only documents which contains  
category: ['a']. I did not found an out-of-box solution there in docs. As a  
workaround I can store categories number in a separate field, but is there  
more clear solution?

--

---

<div class="post-metadata">

**Author:** ![Eugene\_Nikolaev](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@Eugene\_Nikolaev](https://discuss.elastic.co/u/Eugene_Nikolaev)\
**Post date:** [November 21, 2012, 2:42pm UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777/2 "2012-11-21T14:42:10Z")

</div>

It could be something like maximum\_match: 1 🙂

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 21, 2012, 4:10pm UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777/3 "2012-11-21T16:10:06Z")

</div>

Can you sort categories alphabetically, concatenate them and store as a  
single not-analyzed field? So, ['a', 'b', 'c'] would be stored as "a|b|c",  
['c', 'a'] would be stored as "a|c" and ["a"] would be stored as "a". You  
can apply the same conversion to your queries. Then you can search for  
records that contain only categories that you are interested in and nothing  
else.

On Wednesday, November 21, 2012 9:42:10 AM UTC-5, Eugene Nikolaev wrote:

> It could be something like maximum\_match: 1 🙂

--

---

<div class="post-metadata">

**Author:** ![Eugene\_Nikolaev](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@Eugene\_Nikolaev](https://discuss.elastic.co/u/Eugene_Nikolaev)\
**Post date:** [November 21, 2012, 6:58pm UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777/4 "2012-11-21T18:58:01Z")

</div>

Thanks, Igor, good idea! But I am inclined to store array size in a  
separate field. Sorry, I've used a,b,c only for example - real categories  
are a bit more complex than these.

--

---

<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 6, 2017, 3:03am UTC](https://discuss.elastic.co/t/match-only-arrays-having-one-element/9777/5 "2017-07-06T03:03:22Z")

</div>


