# Complex or&missing search

**URL:** <https://discuss.elastic.co/t/complex-or-missing-search/14067>\
**Category:** Elasticsearch\
**Created:** [October 23, 2013, 8:53am UTC](https://discuss.elastic.co/t/complex-or-missing-search/14067 "2013-10-23T08:53:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iulia\_Pasov](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@Iulia\_Pasov](https://discuss.elastic.co/u/Iulia_Pasov)\
**Post date:** [October 23, 2013, 8:53am UTC](https://discuss.elastic.co/t/complex-or-missing-search/14067/1 "2013-10-23T08:53:35Z")

</div>

Hello,

I'm trying to perform a query to obtain all the indexed resources that have  
a particular value for a property or do not have a value for that property.  
It can be generalized to obtaining all the resources that have the value  
for a property in a list of values or they do not have a value for that  
property.  
I tried to do it with filters but it didn't seem to work:  
"query": {

"filtered" : {

"query" : {"match\_all":{}},

"filter" : {

"or" : [

{ "term" : {"property":"value"}},

{"missing" : {"field":"property"}}

]

}

}

}  
I also thought about bool-should queries but I do not know how to use the  
missing filter in it.

Can anyone tell me why my query is wrong and how can I write a proper one?

Thanks,  
Iulia

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 23, 2013, 7:27pm UTC](https://discuss.elastic.co/t/complex-or-missing-search/14067/2 "2013-10-23T19:27:30Z")

</div>

Your query looks fine. Are you getting no results or incorrect results?

Here is a version with a bool filter:

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"should": [  
{  
"term": { "property": "value" }  
},  
{  
"missing": { "field": "user" }  
}  
]  
}  
}  
}  
}  
}

Ivan

On Wed, Oct 23, 2013 at 1:53 AM, Iulia Pasov [iulia.pasov@gmail.com](mailto:iulia.pasov@gmail.com) wrote:

> Hello,
> 
> I'm trying to perform a query to obtain all the indexed resources that  
> have a particular value for a property or do not have a value for that  
> property. It can be generalized to obtaining all the resources that have  
> the value for a property in a list of values or they do not have a value  
> for that property.  
> I tried to do it with filters but it didn't seem to work:  
> "query": {
> 
> "filtered" : {
> 
> "query" : {"match\_all":{}},
> 
> "filter" : {
> 
> "or" : [
> 
> { "term" : {"property":"value"}},
> 
> {"missing" : {"field":"property"}}
> 
> ]
> 
> }
> 
> }
> 
> }  
> I also thought about bool-should queries but I do not know how to use the  
> missing filter in it.
> 
> Can anyone tell me why my query is wrong and how can I write a proper one?
> 
> Thanks,  
> Iulia
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Iulia\_Pasov](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@Iulia\_Pasov](https://discuss.elastic.co/u/Iulia_Pasov)\
**Post date:** [October 24, 2013, 8:30am UTC](https://discuss.elastic.co/t/complex-or-missing-search/14067/3 "2013-10-24T08:30:40Z")

</div>

Thanks Ivan. I thought I was getting incorrect results, but in fact  
somebody else was indexing data at the same time.

On Wednesday, October 23, 2013 11:53:35 AM UTC+3, Iulia Pasov wrote:

> Hello,
> 
> I'm trying to perform a query to obtain all the indexed resources that  
> have a particular value for a property or do not have a value for that  
> property. It can be generalized to obtaining all the resources that have  
> the value for a property in a list of values or they do not have a value  
> for that property.  
> I tried to do it with filters but it didn't seem to work:  
> "query": {
> 
> "filtered" : {
> 
> "query" : {"match\_all":{}},
> 
> "filter" : {
> 
> "or" : [
> 
> { "term" : {"property":"value"}},
> 
> {"missing" : {"field":"property"}}
> 
> ]
> 
> }
> 
> }
> 
> }  
> I also thought about bool-should queries but I do not know how to use the  
> missing filter in it.
> 
> Can anyone tell me why my query is wrong and how can I write a proper one?
> 
> Thanks,  
> Iulia

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:10am UTC](https://discuss.elastic.co/t/complex-or-missing-search/14067/4 "2017-07-06T02:10:51Z")

</div>


