# Nested text phrase query

**URL:** <https://discuss.elastic.co/t/nested-text-phrase-query/7287>\
**Category:** Elasticsearch\
**Created:** [April 10, 2012, 11:46pm UTC](https://discuss.elastic.co/t/nested-text-phrase-query/7287 "2012-04-10T23:46:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benmccann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benmccann/32/420_2.png) [@benmccann](https://discuss.elastic.co/u/benmccann)\
**Post date:** [April 10, 2012, 11:46pm UTC](https://discuss.elastic.co/t/nested-text-phrase-query/7287/1 "2012-04-10T23:46:00Z")

</div>

I can create a query for a nested field on the command line and get the  
result I expected:  
[http://localhost:9200/connectifier/conn/\_search?q=phoneNumbers.canonical:12533813364](http://localhost:9200/connectifier/conn/_search?q=phoneNumbers.canonical:12533813364)

However, I'm not sure how to do this with the Java client. I tried the  
following and got back zero results:  
SearchRequest request = new SearchRequest("connectifier")  
.types("conn")  
.source(new SearchSourceBuilder()  
.query(QueryBuilders.textPhraseQuery("phoneNumbers.canonical",  
"12533813364")));

Is this not how you represent a nested field from the Java client?

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![benmccann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benmccann/32/420_2.png) [@benmccann](https://discuss.elastic.co/u/benmccann)\
**Post date:** [April 11, 2012, 1:32am UTC](https://discuss.elastic.co/t/nested-text-phrase-query/7287/2 "2012-04-11T01:32:39Z")

</div>

Nevermind, stupid mistake on my end. The code I wrote here does work.

On Tuesday, April 10, 2012 4:46:00 PM UTC-7, Ben McCann wrote:

> I can create a query for a nested field on the command line and get the  
> result I expected:
> 
> [http://localhost:9200/connectifier/conn/\_search?q=phoneNumbers.canonical:12533813364](http://localhost:9200/connectifier/conn/_search?q=phoneNumbers.canonical:12533813364)
> 
> However, I'm not sure how to do this with the Java client. I tried the  
> following and got back zero results:  
> SearchRequest request = new SearchRequest("connectifier")  
> .types("conn")  
> .source(new SearchSourceBuilder()  
> .query(QueryBuilders.textPhraseQuery("phoneNumbers.canonical",  
> "12533813364")));
> 
> Is this not how you represent a nested field from the Java client?
> 
> Thanks,  
> Ben

---

<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:33am UTC](https://discuss.elastic.co/t/nested-text-phrase-query/7287/3 "2017-07-06T03:33:03Z")

</div>


