# Match specific value or empty

**URL:** <https://discuss.elastic.co/t/match-specific-value-or-empty/9541>\
**Category:** Elasticsearch\
**Created:** [November 3, 2012, 11:51am UTC](https://discuss.elastic.co/t/match-specific-value-or-empty/9541 "2012-11-03T11:51:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greg_h/32/2659_2.png) [@Greg\_H](https://discuss.elastic.co/u/Greg_H)\
**Post date:** [November 3, 2012, 11:51am UTC](https://discuss.elastic.co/t/match-specific-value-or-empty/9541/1 "2012-11-03T11:51:50Z")

</div>

I'm a bit new to this, but I'm trying to figure out how to write a query  
for a field that gets all results that either match a specific string, or  
have that field blank. I seem to be able to do one or the other, but not  
both. Is there a solution to this?

Thanks,  
Greg

--

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [November 3, 2012, 1:46pm UTC](https://discuss.elastic.co/t/match-specific-value-or-empty/9541/2 "2012-11-03T13:46:12Z")

</div>

hey greg:

this should do the job:

{  
"bool" : {  
"should" : { "term" : { "yourfield" : "yourvalue" }},  
"should" : { "constant\_score" : { "filter" : { "missing" : { "field" : "yourfield" }}}} }  
}

simon  
On Saturday, November 3, 2012 12:51:50 PM UTC+1, Greg H wrote:

> I'm a bit new to this, but I'm trying to figure out how to write a query  
> for a field that gets all results that either match a specific string, or  
> have that field blank. I seem to be able to do one or the other, but not  
> both. Is there a solution to this?
> 
> Thanks,  
> Greg

--

---

<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:06am UTC](https://discuss.elastic.co/t/match-specific-value-or-empty/9541/3 "2017-07-06T03:06:20Z")

</div>


