# Prefix Query and Nested Object exists condition

**URL:** <https://discuss.elastic.co/t/prefix-query-and-nested-object-exists-condition/60635>\
**Category:** Elasticsearch\
**Created:** [September 15, 2016, 4:57pm UTC](https://discuss.elastic.co/t/prefix-query-and-nested-object-exists-condition/60635 "2016-09-15T16:57:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chakkasm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chakkasm](https://discuss.elastic.co/u/chakkasm)\
**Post date:** [September 15, 2016, 4:57pm UTC](https://discuss.elastic.co/t/prefix-query-and-nested-object-exists-condition/60635/1 "2016-09-15T16:57:08Z")

</div>

Hi

I have my index defined as

"person": {  
"firstName": { "type": "string"},  
"lastName": { "type": "string" },  
"email": {  
"type": "nested",  
"properties": {  
"address": {"type": "string" }

This is like one person can have zero to many email address.

I would like to write a query which will do a prefix match of either first name, last name, or email, and should have at least one email address for the matching person first name or last name.

I know how to apply exist query condition, but not able to apply filter with should clause on first name or last name...

{  
"query" : {  
"nested" : {  
"path" : "email",  
"query" : { "match\_all" : { } },  
"filter" : {  
"exists" : { "field" : "email.address" }  
}  
}  
}  
}

eg:

1. firstName: "jack" lastName: "John" with no email should bring zero rows..when searchText is "jac"..even though this is matching firstname using prefix condition.

2. firstName: "andrew", lastName: "John" with an email: [andrew.john@example.com](mailto:andrew.john@example.com)  
should bring the above row..when searchText is "and"

Using elasticsearch 2.3.4.. Appreciate any direction to this

---

<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 5, 2017, 10:19pm UTC](https://discuss.elastic.co/t/prefix-query-and-nested-object-exists-condition/60635/2 "2017-07-05T22:19:56Z")

</div>

Closed on July 5, 2017, 10:19pm UTC


