# Span queries

**URL:** <https://discuss.elastic.co/t/span-queries/117352>\
**Category:** Elasticsearch\
**Created:** [January 28, 2018, 10:15am UTC](https://discuss.elastic.co/t/span-queries/117352 "2018-01-28T10:15:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Chaurasia](https://avatars.discourse-cdn.com/v4/letter/v/ba8739/32.png) [@Vishal\_Chaurasia](https://discuss.elastic.co/u/Vishal_Chaurasia)\
**Post date:** [January 28, 2018, 10:15am UTC](https://discuss.elastic.co/t/span-queries/117352/1 "2018-01-28T10:15:11Z")

</div>

I want to perform span query on different field.  
Use case is like this, i have firstname and lastname indexed and i want to perform fuzzy search first on firstname and then lastname.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 28, 2018, 10:32am UTC](https://discuss.elastic.co/t/span-queries/117352/2 "2018-01-28T10:32:41Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

Using fuzzy parameter in the match query should work well unless I don't understand the exact use case in which case providing an example is helpful.

---

<div class="post-metadata">

**Author:** ![Vishal\_Chaurasia](https://avatars.discourse-cdn.com/v4/letter/v/ba8739/32.png) [@Vishal\_Chaurasia](https://discuss.elastic.co/u/Vishal_Chaurasia)\
**Post date:** [January 28, 2018, 10:35am UTC](https://discuss.elastic.co/t/span-queries/117352/3 "2018-01-28T10:35:33Z")

</div>

I have user mappings as follow-  
{  
"mappings":{  
"viewer":{  
"properties":{  
"type":{  
"type":"text"  
},  
"first\_name":{  
"type":"text"  
},  
"last\_name":{  
"type":"text"  
},  
"email":{  
"type":"keyword"  
}  
}  
}  
},  
"settings":{  
"analysis":{  
"analyzer":{  
"default":{  
"type":"standard"  
}  
}  
}  
}  
}

Now i want to perform fuzzy search on first\_name and last\_name, term query on email.  
Suppose if user types "Chris Pitt", then i want to do fuzzy match chris on first\_name and pitt on last\_name, but if the input is only "chris" then i will only go for first\_name fuzzy match and term email query.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 28, 2018, 10:51am UTC](https://discuss.elastic.co/t/span-queries/117352/4 "2018-01-28T10:51:01Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

Please edit your post.

And provide a script we can fully run to reproduce what you are asking for.

---

<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:** [February 25, 2018, 10:51am UTC](https://discuss.elastic.co/t/span-queries/117352/5 "2018-02-25T10:51:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
