# Nested objectes query problem

**URL:** <https://discuss.elastic.co/t/nested-objectes-query-problem/9619>\
**Category:** Elasticsearch\
**Created:** [November 8, 2012, 5:25am UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9619 "2012-11-08T05:25:35Z")\
**Posts on this page:** 3\
**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, 5:25am UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9619/1 "2012-11-08T05:25:35Z")

</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,  
Bhushan

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [November 8, 2012, 2:23pm UTC](https://discuss.elastic.co/t/nested-objectes-query-problem/9619/2 "2012-11-08T14:23:11Z")

</div>

> 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 ?  
> How do you send the above json example as document to ES?

> 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.  
> Can you share the how you're currently doing this? What you're  
> describing should work.

> 1. How can i define facet on fields color1, color2 present in  
> vehicles.vehicle  
> Are color1 and color2 the same logical property in your domain? If so  
> why not index these colors in one field? The terms facet does support  
> creating facet counts from multiple fields:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html)

Martijn

--

---

<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/9619/3 "2017-07-06T03:05:21Z")

</div>


