# Nested objectes query problem

**URL:** <https://discuss.elastic.co/t/nested-objectes-query-problem/9618>\
**Category:** Elasticsearch\
**Created:** [November 8, 2012, 4:56am UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9618 "2012-11-08T04:56:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chavan15](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@chavan15](https://discuss.elastic.co/u/chavan15)\
**Post date:** [November 8, 2012, 4:56am UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9618/1 "2012-11-08T04:56:31Z")

</div>

I am using Java API to query elastic search index. I have indexed data having complex structure through Couchbase into ElasticSearch. My data is as follows :

e.g.

{  
"detail": {  
"lastName": "JOSEPH",  
"firstName": "JOHN",  
"birthDate": "19621022",  
"gender": "M"  
},  
"vehicles": {  
"vehicle": [  
{  
"state": "CA",  
"model": "RAPIDE",  
"color1": "BGE",  
"color2": "BLK",  
"licensePlate": "cdgh34676",  
"make": "ASTONMARTIN"  
},  
{  
"state": "LA",  
"model": "AUDI",  
"color1": "BGE",  
"color2": "BLK",  
"licensePlate": "abcd1209",  
"make": "ASTONMARTIN"  
}

```
    ]

```

}  
}

My Questions are:

1. I am querying using:

client.prepareSearch("index\_name").setTypes("couchbaseDocument").setQuery(QueryBuilders.fieldQuery("detail.lastName", "JOSEPH"))).execute().actionGet();

It returns 0 hits but if i set QueryBuilders.fieldQuery("lastName", "JOSEPH") it returns the result with hit count 1 ?

1. Can i define Facet on say gender present in detail using .addFacet() and adding field as detail.lastName. In my case this is also not working.

2. How can i define facet on fields color1, color2 present in vehicles.vehicle

Thanks,  
Chavan15

---

<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:05am UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9618/2 "2017-07-06T03:05:32Z")

</div>


