# Elastic search match query over array object

**URL:** <https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786>\
**Category:** Elasticsearch\
**Created:** [October 2, 2020, 12:32pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786 "2020-10-02T12:32:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aninda\_halder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aninda_halder/32/68707_2.png) [@aninda\_halder](https://discuss.elastic.co/u/aninda_halder)\
**Post date:** [October 2, 2020, 12:32pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786/1 "2020-10-02T12:32:36Z")

</div>

Suppose i've 3 doc

```auto
doc_1 = {
    "citedIn": [
        "Bar Councils Act, 1926 - Section 15",
        "Contract Act, 1872 - Section 23"
    ]
}

doc_2 = {
    "citedIn":[
        "15 C. B 400", 
        "Contract Act, 1872 - Section 55"
    ]
}

doc_3 = {
    "citedIn":[
        "15 C. B 400", 
        "Contract Act, 1872 - Section 15"
    ]
}

```

Here `citedIn` field is a array object.Now i want run a stander `match` query

```auto
{
    "query":
    {
        "match": {"citedIn":{"query": "Contract act 15" , "operator":"and" }}
    }

}

```

The above query return all of the 3 doc, but it suppose to return `doc_3` as only `doc_3` contain `Contract`, `act` and `15` together in a single array element .

i also did try nested field.  
This Is my mapping

```auto
{
    "mappings": {
        "properties": {
            "citedIn": {
                "type": "nested",
                "include_in_parent": true,
                "properties": {
                    "someFiled": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
}

```

This is my data

```auto
doc_1 = {
    "citedIn": [
        {"someFiled" : "Bar Councils Act, 1926 - Section 15"},
        {"someFiled" : "Contract Act, 1872 - Section 23"}
    ]
}

doc_2 = {
    "citedIn":[
        {"someFiled" : "15 C. B 400"}
        {"someFiled" : "Contract Act, 1872 - Section 55"}
    ]
}

doc_3 = {
    "citedIn":[
        {"someFiled" : "15 C. B 400"},
        {"someFiled" : "Contract Act, 1872 - Section 15"}
    ]
}

```

This is my query

```auto
{
    "query":
    {

        "match": {"citedIn.someFiled":{"query": "Contract act 15" , "operator":"and" }}
            
        
    }
}

```

But still getting same result .

How would i achieve this ?

Any suggestion/Solution would be preferable

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 5, 2020, 9:20am UTC](https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786/2 "2020-10-05T09:20:55Z")

</div>

Hey,

you also need to wrap the `match` query within a `nested` query. See [https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-nested-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-nested-query.html) - not sure if you did this.

Also, please a provide a fully reproducible example, that others can copy&paste into the kibana dev tools console. It's easier to test than incomplete snippets of programming languages... THanks!

---

<div class="post-metadata">

**Author:** ![aninda\_halder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aninda_halder/32/68707_2.png) [@aninda\_halder](https://discuss.elastic.co/u/aninda_halder)\
**Post date:** [October 14, 2020, 10:23am UTC](https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786/3 "2020-10-14T10:23:53Z")

</div>

Solved the issue wth [Nested Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.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:** [November 11, 2020, 10:24am UTC](https://discuss.elastic.co/t/elastic-search-match-query-over-array-object/250786/4 "2020-11-11T10:24:14Z")

</div>

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