# How to match exactly one item in an array

**URL:** https://discuss.elastic.co/t/how-to-match-exactly-one-item-in-an-array/157220
**Category:** Elasticsearch
**Created:** [November 18, 2018, 11:38am UTC](https://discuss.elastic.co/t/how-to-match-exactly-one-item-in-an-array/157220 "2018-11-18T11:38:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AlloVince](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allovince/32/35472_2.png) [@AlloVince](https://discuss.elastic.co/u/AlloVince)
#### Post date: [November 18, 2018, 11:38am UTC](https://discuss.elastic.co/t/how-to-match-exactly-one-item-in-an-array/157220/1 "2018-11-18T11:38:52Z")

</div>

Hi guys

I have a question when matching a field with array.

Here is my data:

Item1:

```auto
{
 "names": ["foo-123-sth-more", "bar-456-sth-more"]
}

```

Item2:

```auto
{
 "names": ["foo-456-sth-more", "bar-123-sth-more"]
}

```

My query is

```auto
{
    "query": {
        "match" : {
            "names" : {
                "query" : "foo 456",
                "operator" : "and"
            }
        }
    }
}

```

Both item1 and item2 will matched, but the expected result is only item2 match, every element in array should be consider as an independent text to handle.

Is there any one could tell me how to handle this case? thank you.

---

<div class="post-metadata">

### Author: ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)
#### Post date: [November 20, 2018, 6:33pm UTC](https://discuss.elastic.co/t/how-to-match-exactly-one-item-in-an-array/157220/2 "2018-11-20T18:33:15Z")

</div>

You should use nested datatypes. It is just the way arrays are indexed that shows the behaviour are you noticing.  
Check this out - [https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html)

---

<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: [December 18, 2018, 6:33pm UTC](https://discuss.elastic.co/t/how-to-match-exactly-one-item-in-an-array/157220/3 "2018-12-18T18:33:22Z")

</div>

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