# Unable to search with child object

**URL:** <https://discuss.elastic.co/t/unable-to-search-with-child-object/62642>\
**Category:** Elasticsearch\
**Created:** [October 10, 2016, 3:11pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642 "2016-10-10T15:11:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinayak\_Fulari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_fulari/32/12114_2.png) [@Vinayak\_Fulari](https://discuss.elastic.co/u/Vinayak_Fulari)\
**Post date:** [October 10, 2016, 3:11pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/1 "2016-10-10T15:11:59Z")

</div>

Hi,

In my scenario I am storing whole dynamoDB event into elastic search, now I want to get whole event by querying it.

Sharing below my index-document structure as well as my json query. What should be my json query to get matching hits on the basis of " **CustomerId**"

Kindly reply as soon as possible. Thanking you in anticipation. ...

```auto
{
  "took": 19,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1111,
    "max_score": 1,
    "hits": [
      {
        "_index": "promotion_events",
        "_type": "event",
        "_id": "xxxxxxxxxxxx",
        "_score": 1,
        "_source": {
          "eventId": "xxxxxxxxxx",
          "record": {
            "eventSourceARN": "arn:aws:dynamodb:xxxxxxxxxxxxxxxxxxxxx",
            "eventID": "xxxxxxxxxxxxxxxx",
            "eventName": "INSERT",
            "eventVersion": "1.1",
            "eventSource": "aws:dynamodb",
            "awsRegion": "xxxxx",
            "dynamodb": {
              "keys": {
                "id": { "s": "xxxxxxxxxxxxxxxxxxxxxx" } },
              "newImage": {
                "promotionType": { "s": "xxxxx" },
                "enddate": { "s": "xxxxxx" },
                "productid": { "s": "0" },
                "campaignid": { "s": "xxxxxx" },
                " **customerid**": { "s": "xxxxxxx" },
                "id": { "s": "xxxxxxxxxxxxx" },
                "promoid": { "s": "xxxxxxxxxxxxxxx" },
                "source": { "s": "xxxxxxx" },
                "startdate": { "s": "xxxxxxxxx" },
                "storeid": { "s": "0" },
                "barcodeid": { "s": "xxxxxxx" },
                "timestamp": { "s": "xxxxxxxxxxxxxxx" }
              },
              "sequenceNumber": "xxxxxxxxxxxxxxxxx",
              "sizeBytes": 9031,
              "streamViewType": "NEW_AND_OLD_IMAGES"
            }
          }
        }
      }
]
}
}

```

**My Json Query:**

```auto
{
  "_source": {
    "include": ["record.*"]
  },
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "term": {
          "record.dynamodb.newImage.customerid": "xxxxxxx"
        }
      }
    }
  }
}

```

**Output:**  
code : 200 , count :0  
{"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 11, 2016, 3:32pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/2 "2016-10-11T15:32:37Z")

</div>

I took the liberty to edit your post to have some structure for the json part. You can do that by inserting 3 backticks (`) before and after your code.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 11, 2016, 3:34pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/3 "2016-10-11T15:34:22Z")

</div>

How does the mapping look like?

---

<div class="post-metadata">

**Author:** ![Vinayak\_Fulari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_fulari/32/12114_2.png) [@Vinayak\_Fulari](https://discuss.elastic.co/u/Vinayak_Fulari)\
**Post date:** [October 12, 2016, 10:11am UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/4 "2016-10-12T10:11:36Z")

</div>

**Tanks for your reply**  
{"promotion\_events":{"mappings":{"event":{"properties":{"eventId":{"type":"string"},"record":{"properties":{"awsRegion":{"type":"string"},"dynamodb":{"properties":{"keys":{"properties":{"id":{"properties":{"s":{"type":"string"}}}}},"newImage":{"properties":{"barcodeid":{"properties":{"s":{"type":"string"}}},"campaignid":{"properties":{"s":{"type":"string"}}},"customerid":{"properties":{"s":{"type":"string"}}},"enddate":{"properties":{"s":{"type":"string"}}},"id":{"properties":{"s":{"type":"string"}}},"marketingType":{"properties":{"m":{"properties":{"id":{"properties":{"s":{"type":"string"}}},"metadata":{"properties":{"m":{"properties":{"marketingAttributes":{"properties":{"m":{"properties":{"description":{"properties":{"s":{"type":"string"}}},"id":{"properties":{"s":{"type":"string"}}},"image":{"type":"object"},"name":{"properties":{"s":{"type":"string"}}},"offerValue":{"properties":{"s":{"type":"string"}}},"previousPrice":{"properties":{"s":{"type":"string"}}},"price":{"properties":{"s":{"type":"string"}}},"sellingUOM":{"properties":{"s":{"type":"string"}}}}}}},"source":{"properties":{"m":{"properties":{"description":{"properties":{"s":{"type":"string"}}},"name":{"properties":{"s":{"type":"string"}}},"sourceId":{"properties":{"s":{"type":"string"}}}}}}}}}}},"promotionActive":{"properties":{"m":{"properties":{"endDate":{"properties":{"s":{"type":"string"}}},"startDate":{"properties":{"s":{"type":"string"}}}}}}},"promotionType":{"properties":{"s":{"type":"string"}}},"reward":{"properties":{"l":{"properties":{"m":{"properties":{"id":{"properties":{"n":{"type":"string"}}}}}}}}}}}}},"productid":{"properties":{"s":{"type":"string"}}},"promoid":{"properties":{"s":{"type":"string"}}},"promotionType":{"properties":{"s":{"type":"string"}}},"source":{"properties":{"s":{"type":"string"}}},"startdate":{"properties":{"s":{"type":"string"}}},"storeid":{"properties":{"s":{"type":"string"}}},"timestamp":{"properties":{"s":{"type":"date","format":"strict\_date\_optional\_time||epoch\_millis"}}}}},"oldImage":{"properties":{"barcodeid":{"properties":{"s":{"type":"string"}}},"campaignid":{"properties":{"s":{"type":"string"}}},"customerid":{"properties":{"s":{"type":"string"}}},"enddate":{"properties":{"s":{"type":"string"}}},"id":{"properties":{"s":{"type":"string"}}},"marketingType":{"properties":{"m":{"properties":{"id":{"properties":{"s":{"type":"string"}}},"metadata":{"properties":{"m":{"properties":{"marketingAttributes":{"properties":{"m":{"properties":{"description":{"properties":{"s":{"type":"string"}}},"id":{"properties":{"s":{"type":"string"}}},"image":{"type":"object"},"name":{"properties":{"s":{"type":"string"}}},"offerValue":{"properties":{"s":{"type":"string"}}},"previousPrice":{"properties":{"s":{"type":"string"}}},"price":{"properties":{"s":{"type":"string"}}},"sellingUOM":{"properties":{"s":{"type":"string"}}}}}}},"source":{"properties":{"m":{"properties":{"description":{"properties":{"s":{"type":"string"}}},"name":{"properties":{"s":{"type":"string"}}},"sourceId":{"properties":{"s":{"type":"string"}}}}}}}}}}},"promotionActive":{"properties":{"m":{"properties":{"endDate":{"properties":{"s":{"type":"string"}}},"startDate":{"properties":{"s":{"type":"string"}}}}}}},"promotionType":{"properties":{"s":{"type":"string"}}},"reward":{"properties":{"l":{"properties":{"m":{"properties":{"id":{"properties":{"n":{"type":"string"}}}}}}}}}}}}},"productid":{"properties":{"s":{"type":"string"}}},"promoid":{"properties":{"s":{"type":"string"}}},"promotionType":{"properties":{"s":{"type":"string"}}},"source":{"properties":{"s":{"type":"string"}}},"startdate":{"properties":{"s":{"type":"string"}}},"storeid":{"properties":{"s":{"type":"string"}}},"timestamp":{"properties":{"s":{"type":"date","format":"strict\_date\_optional\_time||epoch\_millis"}}}}},"sequenceNumber":{"type":"string"},"sizeBytes":{"type":"long"},"streamViewType":{"type":"string"}}},"eventID":{"type":"string"},"eventName":{"type":"string"},"eventSource":{"type":"string"},"eventSourceARN":{"type":"string"},"eventVersion":{"type":"string"}}}}}}}}

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 12, 2016, 10:38am UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/5 "2016-10-12T10:38:33Z")

</div>

Hi,

I'm afraid this is impossible to read for me. Can you please use a tool like [http://jsonlint.com](http://jsonlint.com) or something similar in the future to format you output? And use the 3 backticks (`) before and after your code as I mentioned above?

In any case, I spotted that your `customerid` mapping looks like this:

```auto
"customerid": {
    "properties": {
        "s": {
            "type": "string"
        }
    }
}

```

So there seems to be this little `s` field inside each mapping that you should probably consider when writing your queries. Having said that, the mapping looks somewhat auto-generated from some database schema and looks quiet deep to me. I'm not sure if I'd expect it to work terribly well with this level of nesting.

---

<div class="post-metadata">

**Author:** ![Vinayak\_Fulari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_fulari/32/12114_2.png) [@Vinayak\_Fulari](https://discuss.elastic.co/u/Vinayak_Fulari)\
**Post date:** [October 12, 2016, 4:37pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/6 "2016-10-12T16:37:00Z")

</div>

🙂  
I can understand, but this textbox has only 5000 character capacity, so no option left with me. I would like to suggest you to copy this json text into your formating tool it will give you formatted json.  
And you are right its generated mapping from dynamoDb Streams.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 13, 2016, 5:55am UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/7 "2016-10-13T05:55:17Z")

</div>

If the formatted version is too big, post it as a gist on GitHub (or use some other service) and link to it instead.

---

<div class="post-metadata">

**Author:** ![wanglifengwf](https://avatars.discourse-cdn.com/v4/letter/w/41988e/32.png) [@wanglifengwf](https://discuss.elastic.co/u/wanglifengwf)\
**Post date:** [October 13, 2016, 6:04am UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/8 "2016-10-13T06:04:41Z")

</div>

what is 's'?  
please use this instead!

```auto
"customerid": {
       "type": "string"
}

{
  "_source": {
    "include": ["record.*"]
  },
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "term": {
          "record.dynamodb.newImage.customerid": "xxxxxxx"
        }
      }
    }
  }
}

```

---

<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:** [July 5, 2017, 10:12pm UTC](https://discuss.elastic.co/t/unable-to-search-with-child-object/62642/9 "2017-07-05T22:12:47Z")

</div>


