# Unable to search nested object with correct format

**URL:** <https://discuss.elastic.co/t/unable-to-search-nested-object-with-correct-format/262615>\
**Category:** Elasticsearch\
**Created:** [January 29, 2021, 8:26am UTC](https://discuss.elastic.co/t/unable-to-search-nested-object-with-correct-format/262615 "2021-01-29T08:26:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ycbencheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ycbencheng/32/83102_2.png) [@ycbencheng](https://discuss.elastic.co/u/ycbencheng)\
**Post date:** [January 29, 2021, 8:26am UTC](https://discuss.elastic.co/t/unable-to-search-nested-object-with-correct-format/262615/1 "2021-01-29T08:26:04Z")

</div>

Hi ELK community,  
I'm unable to get the nested `prospects` obj within the vehicle index.

Here is the suppose index obj -

```auto
      {
        "_index" : "vehicles",
        "_type" : "_doc",
        "_id" : "3MZBxxxxxxx",
        "_score" : 0.0,
        "_source" : {
          "vin" : "3MZBxxxxxxx",
          "make" : "mazda",
          "model" : "mazda3",
          "color" : "unknown",
          "year" : 2018,
          "vehicle" : "2018 mazda mazda3",
          "trim" : "grand touring",
          "estimated_mileage" : null,
          "dealership" : [
            209
          ],
          "current_owner_group_id" : null,
          "current_owner_customer_id" : null,
          "last_service_date" : null,
          "last_service_revenue" : null,
          "purchase_type" : [],
          "in_service_date" : null,
          "deal_headers" : [],
          "services" : [],
          "customers" : [],
          "salesmen" : null,
          "service_appointments" : [],
          "prospects" : [
            {
              "first_name" : "Kammy",
              "last_name" : "Maytag",
              "name" : "Kammy Maytag",
              "company_name" : null,
              "emails" : [],
              "phone_numbers" : [],
              "address" : "31119 field",
              "city" : "helen",
              "state" : "keller",
              "zip" : "81411",
              "within_dealership_aoi_region" : true,
              "dealership_ids" : [
                209
              ],
              "dealership_dppa_protected_ids" : [
                209
              ],
              "registration_id" : 12344,
              "id" : 1054,
              "prospect_source_id" : "12344",
              "type" : "Prospect"
            }
          ]
        }
      }
    ]
  }
}

```

Here is how I'm trying to get it -

```auto
 GET /vehicles/_search
{
  "query": {
    "bool": {
      "must": { "match_all": {} },
      "filter": [
        { "term": { "dealership": "209" } },
        {
          "nested": {
            "path": "prospects",
            "query": {
              "bool": {
                "must": [
                  { "term": { "prospects.first_name": "Kammy" } },
                  { "term": { "prospects.dealership": "209" } },
                  { "term": { "prospects.type": "Prospect" } }
                ]
              }
            }
          }
        },
        { "bool": { "must_not": { "term": { "purchase_type": "Wholesale" } } } }
      ]
    }
  },
  "sort": [{ "_doc": { "order": "asc" } }]
}

```

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [January 30, 2021, 5:39pm UTC](https://discuss.elastic.co/t/unable-to-search-nested-object-with-correct-format/262615/2 "2021-01-30T17:39:46Z")

</div>

What does your mapping look like?

The error is saying `[nested] nested object under path [prospects] is not of nested type` when I tested this. Are you getting a different error?

It is saying that `prospects` needs to be [type nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) in the mapping if you want to search using a nested query.

---

<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:** [February 27, 2021, 5:39pm UTC](https://discuss.elastic.co/t/unable-to-search-nested-object-with-correct-format/262615/3 "2021-02-27T17:39:57Z")

</div>

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