# Nested object query

**URL:** <https://discuss.elastic.co/t/nested-object-query/4912>\
**Category:** Elasticsearch\
**Created:** [July 20, 2011, 5:16pm UTC](https://discuss.elastic.co/t/nested-object-query/4912 "2011-07-20T17:16:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsolakp](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@tsolakp](https://discuss.elastic.co/u/tsolakp)\
**Post date:** [July 20, 2011, 5:16pm UTC](https://discuss.elastic.co/t/nested-object-query/4912/1 "2011-07-20T17:16:29Z")

</div>

- deleted -

---

<div class="post-metadata">

**Author:** ![tsolakp](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@tsolakp](https://discuss.elastic.co/u/tsolakp)\
**Post date:** [July 22, 2011, 10:05pm UTC](https://discuss.elastic.co/t/nested-object-query/4912/2 "2011-07-22T22:05:00Z")

</div>



---

<div class="post-metadata">

**Author:** ![ofavre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofavre/32/116819_2.png) [@ofavre](https://discuss.elastic.co/u/ofavre)\
**Post date:** [July 25, 2011, 7:40am UTC](https://discuss.elastic.co/t/nested-object-query/4912/3 "2011-07-25T07:40:16Z")

</div>

Like your title says: use "nested" queries:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Don't forget to define you're mapping accordingly:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

(The link on the first page to the second is broken in the docs)

--  
Olivier Favre

[www.yakaz.com](http://www.yakaz.com)

2011/7/20 tsolakp [via Elasticsearch Users] \<  
[ml-node+3186014-13754093-393975@n3.nabble.com](mailto:ml-node+3186014-13754093-393975@n3.nabble.com)\>

> I have a query like this:
> 
> Date date = DateUtils.parseDate( _"2004-11-23T07:00:00.000-0000"_, new  
> String{"yyyy-MM-dd'T'hh:mm:ss.sssZ"} );
> 
> ```
> SearchResponse response = client.prepareSearch("props")
> .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> .setQuery( boolQuery().must( fieldQuery("property.sales.price", *
> 
> ```
> 
> 135000\* ) ).must( fieldQuery("property.sales.saleDate", date.getTime() ) )  
> )  
> .setFrom(0).setSize(60).setExplain(true)  
> .execute()  
> .actionGet();
> 
> which returns the following single document:
> 
> {property={suitableForModeling=Y, location={lon=-104.930714,  
> lat=39.700083}, bathrooms=1, propStyle:r=R, bedrooms=2, price=135000,  
> lastSalePrice=135000,\* sales=[{price=135000,  
> saleDate=2009-09-08T06:00:00.000Z}, {price=142900,  
> saleDate=2004-11-23T07:00:00.000Z}]\*, propType=CND, yoc=1982,  
> saleDate=2009-09-08T06:00:00.000Z, acres=0.01, mainSqft=745}}
> 
> How can I tell ES to apply query to one "property.sales" at a time. What I  
> want is not get any hits with the above query since first sale does not have  
> saleDate of _"2004-11-23T07:00:00.000-0000"_.
> 
> * * *
> 
> If you reply to this email, your message will be added to the discussion  
> below:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Nested-object-query-tp3186014p3186014.html](http://elasticsearch-users.115913.n3.nabble.com/Nested-object-query-tp3186014p3186014.html)  
> To start a new topic under Elasticsearch Users, email  
> [ml-node+115913-1699315842-393975@n3.nabble.com](mailto:ml-node+115913-1699315842-393975@n3.nabble.com)  
> To unsubscribe from Elasticsearch Users, click here[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe\_by\_code&node=115913&code=b2xpdmllckB5YWthei5jb218MTE1OTEzfDIxMjI2MTYwOTc=](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=115913&code=b2xpdmllckB5YWthei5jb218MTE1OTEzfDIxMjI2MTYwOTc=).

---

<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 6, 2017, 3:59am UTC](https://discuss.elastic.co/t/nested-object-query/4912/4 "2017-07-06T03:59:38Z")

</div>

Closed on July 6, 2017, 3:59am UTC


