# How to search in array of objects

**URL:** <https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225>\
**Category:** Elasticsearch\
**Created:** [February 27, 2020, 11:49am UTC](https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225 "2020-02-27T11:49:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 27, 2020, 11:49am UTC](https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225/1 "2020-02-27T11:49:09Z")

</div>

Current version of ElasticSearch & Kibana 7.6.0

Hello folks! this is my template:

```auto
GET _template/my_template
"mappings" : {
      "_meta" : { },
      "_source" : { },
      "properties" : {
        "brands" : {
          "type" : "nested",
          "properties" : {
            "assessment" : {
              "type" : "float"
            },
            "quantity" : {
              "type" : "integer"
            },
            "name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "integer"
            }
          }
        },
        "taxonomies" : {
          "type" : "nested",
          "properties" : {
            "path" : {
              "type" : "text"
            },
            "assessment" : {
              "type" : "float"
            },
            "quantity" : {
              "type" : "integer"
            },
            "name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "integer"
            }
          }
        },
        "categories" : {
          "type" : "nested",
          "properties" : {
            "assessment" : {
              "type" : "float"
            },
            "quantity" : {
              "type" : "integer"
            },
            "name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "integer"
            }
          }
        },
        "warehouse" : {
          "type" : "object",
          "properties" : {
            "name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "integer"
            }
          }
        },
        "assesment" : {
          "type" : "float"
        }
      }
    }

```

I tried to follow this guide [Nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) and this one [Nested Query](https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-query.html). I tried to use the same documents from example but nothing... It return all values. In my documents what I trying to get is all Brands with Id = 1, this is my query:

```auto
GET remake/_search
  "_source": ["brands.name","brands.id"], 
  "query": {
    "nested": {
      "path": "brands",
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "brands.id": 1
              }
            }
          ]
        }
      }
    }
  }
}

```

This should return only brands with id = 1, but returns all values. Should I fix the template/mappings? Thanks!

---

<div class="post-metadata">

**Author:** ![tarungargbtp2612](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tarungargbtp2612/32/45903_2.png) [@tarungargbtp2612](https://discuss.elastic.co/u/tarungargbtp2612)\
**Post date:** [February 27, 2020, 12:10pm UTC](https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225/2 "2020-02-27T12:10:46Z")

</div>

I think you are looking for `inner hits`. It will return another field named `inner hits` in your results containing only those brands objects that match you query condition. In the `_source`, the whole document is returned, that is why it has all the brands.

---

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 27, 2020, 12:24pm UTC](https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225/3 "2020-02-27T12:24:58Z")

</div>

Hmmmm... `_source` is like SELECT `column1, column2 FROM remake` in SQL.  
But... Is the template ok?

---

<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 26, 2020, 12:25pm UTC](https://discuss.elastic.co/t/how-to-search-in-array-of-objects/221225/4 "2020-03-26T12:25:02Z")

</div>

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