Unable to search nested object with correct format

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

Here is the suppose index obj -

      {
        "_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 -

 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" } }]
}

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 in the mapping if you want to search using a nested query.

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