# Elasticsearch : search for an array of string values:

**URL:** <https://discuss.elastic.co/t/elasticsearch-search-for-an-array-of-string-values/119188>\
**Category:** Elasticsearch\
**Created:** [February 9, 2018, 8:55am UTC](https://discuss.elastic.co/t/elasticsearch-search-for-an-array-of-string-values/119188 "2018-02-09T08:55:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilzs](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sunilzs](https://discuss.elastic.co/u/sunilzs)\
**Post date:** [February 9, 2018, 8:55am UTC](https://discuss.elastic.co/t/elasticsearch-search-for-an-array-of-string-values/119188/1 "2018-02-09T08:55:55Z")

</div>

I have an index in elasticsearch where the body contains an array of a field with an array of values. For example :

```
{
"took": 0,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 3,
    "max_score": 1,
    "hits": [
    {
        "_index": "families",
        "_type": "family",
        "_id": "o8qxd2EB9CizMt-k15mv",
        "_score": 1,
        "_source": {
        "names": [
            "Jefferson Erickson",
            "Bailee Miller",
            "Ahmed Bray"
        ]
        }
    },
    {
        "_index": "families",
        "_type": "family",
        "_id": "osqxd2EB9CizMt-kfZlJ",
        "_score": 1,
        "_source": {
        "names": [
            "Nia Walsh",
            "Jefferson Erickson",
            "Darryl Stark"
        ]
        }
    },
    {
        "_index": "families",
        "_type": "family",
        "_id": "pMrEd2EB9CizMt-kq5m-",
        "_score": 1,
        "_source": {
        "names": [
            "lia shelton",
            "joanna shaffer",
            "mathias little"
        ]
        }
    }
    ]
}
}

```

Now I need a search query in which I can search for documents from an array of values, something like this:

```
GET /families/_search
{
"query" : {
    "bool" : {
    "filter" : {
        "bool" : {
        "should" : [
            {"match_phrase" : {"names" : ["ahmed bray", "nia walsh"]}}
        ]
        }
    }
    }
}
}

```

And it should return the 2 documents that contain these names like this:

```
{
"took": 0,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 2,
    "max_score": 0,
    "hits": [
    {
        "_index": "families",
        "_type": "family",
        "_id": "o8qxd2EB9CizMt-k15mv",
        "_score": 0,
        "_source": {
        "names": [
            "Jefferson Erickson",
            "Bailee Miller",
            "Ahmed Bray"
        ]
        }
    },
    {
        "_index": "families",
        "_type": "family",
        "_id": "osqxd2EB9CizMt-kfZlJ",
        "_score": 0,
        "_source": {
        "names": [
            "Nia Walsh",
            "Jefferson Erickson",
            "Darryl Stark"
        ]
        }
    }
    ]
}
}

```

How do i make a query like this? I tried using the "terms" keyword but "terms" only allows me to search from an array on single words like this:  
{"terms" : {"names" : ["bray", "nia"]}}

But I need to look using the full names like this:  
{"names" : ["ahmed bray", "nia walsh"]}}

---

<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 9, 2018, 8:55am UTC](https://discuss.elastic.co/t/elasticsearch-search-for-an-array-of-string-values/119188/2 "2018-03-09T08:55:56Z")

</div>

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