# Query a nested object

**URL:** https://discuss.elastic.co/t/query-a-nested-object/180830
**Category:** Elasticsearch
**Created:** [May 13, 2019, 2:28pm UTC](https://discuss.elastic.co/t/query-a-nested-object/180830 "2019-05-13T14:28:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Theodoros\_Moschos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theodoros_moschos/32/46080_2.png) [@Theodoros\_Moschos](https://discuss.elastic.co/u/Theodoros_Moschos)
#### Post date: [May 13, 2019, 2:28pm UTC](https://discuss.elastic.co/t/query-a-nested-object/180830/1 "2019-05-13T14:28:31Z")

</div>

Hello all,

I have got the following document and am trying to query its ids.ema\_id value :

```
{
"took": 5,
"timed_out": false,
"_shards": {
	"total": 5,
	"successful": 5,
	"skipped": 0,
	"failed": 0
},
"hits": {
	"total": 12,
	"max_score": 16.52765,
	"hits": [{
		"_index": "records",
		"_type": "records",
		"_id": "1699",
		"_score": 16.52765,
		"_source": {
			"id": 1699,
			"house_id": null,
			"ids": {
				"ema_id": "GOODMORN11"
			}
		}
	}]
}

```

}

How would that be possible using elasticsearch-php?

Tried several things like `$this->record->search() ->nested('ids', function (SearchBuilder $builder) use ($searchTerm) { $builder->filter()->term('ids.ema_id', $searchTerm); })->size(config('results_per_category'))->get()->hits();`

but no luck.

Any ideas would be highly appreciated!

_Update_ Mappings are as follows:

```auto
	"records": {
		"mappings": {
			"records": {
				"properties": {
					"ids": {
						"type": "nested",
						"properties": {
							"ema_id": {
								"type": "text",
								"fields": {
									"keyword": {
										"type": "keyword",
										"ignore_above": 256
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
```

---

<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: [June 10, 2019, 2:28pm UTC](https://discuss.elastic.co/t/query-a-nested-object/180830/2 "2019-06-10T14:28:49Z")

</div>

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