# Exists operation being ignored when searching

**URL:** <https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028>\
**Category:** Elasticsearch\
**Created:** [October 26, 2015, 9:30pm UTC](https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028 "2015-10-26T21:30:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrepetto](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@mrepetto](https://discuss.elastic.co/u/mrepetto)\
**Post date:** [October 26, 2015, 9:30pm UTC](https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028/1 "2015-10-26T21:30:44Z")

</div>

Hi everyone!

A new noob here with some doubts. I was testing a silly thing with the exists filter, but looks like is not working at all 😕 Look at the example below, when I run it, it completly ignores the exists filter and bring me the only result I have, only when I remove the { "query":{ "match\_all":{} } } it works (giving me 0 results). How is that possible??

POST /test/tweet  
{  
"message": "some arrays in this tweet...",  
"tags": [  
"elasticsearch",  
"wow"  
],  
"lists": [  
{  
"name": "prog\_list",  
"description": "programming list"  
},  
{  
"name": "cool\_list",  
"description": "cool stuff list"  
}  
],  
"numbers": [1,2,3,4]

}

GET /test/tweet/\_search?explain #&format=yaml  
{  
\_source:["lists.description","ttt"],  
"query": {  
"filtered": {  
"filter": [  
{  
"exists": {  
"field": "ttt"  
}  
},  
{  
"query": {  
"match\_all": {}  
}  
}  
]  
}  
}  
}

Thanks!  
Mauricio Repetto

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 27, 2015, 3:51am UTC](https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028/2 "2015-10-27T03:51:42Z")

</div>

You need to wrap the filters in an `and` for them to be both applied, it's not an implicit `or` or `and`.  
If you run;

```auto
POST test/tweet/_validate/query?explain
{
  "query": {
    "filtered": {
      "filter": [
        {
          "exists": {
            "field": "ttt"
          }
        },
        {
          "query": {
            "match_all": {}
          }
        }
      ]
    }
  }
}

```

You will get;

```auto
{
   "valid": true,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "explanations": [
      {
         "index": "test",
         "valid": true,
         "explanation": "filtered(ConstantScore(QueryWrapperFilter(ConstantScore(*:*))))->cache(_type:tweet)"
      }
   ]
}

```

And basically it's saying we ignore the exists and just default to the `match_all`.

This should really return an error as it's invalid for the filter query, we've refactoring things in current master which should help moving forward though.

---

<div class="post-metadata">

**Author:** ![mrepetto](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@mrepetto](https://discuss.elastic.co/u/mrepetto)\
**Post date:** [October 27, 2015, 2:29pm UTC](https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028/3 "2015-10-27T14:29:11Z")

</div>

Thanks for your reply 🙂 I think I get it now Mark!

---

<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, 11:42pm UTC](https://discuss.elastic.co/t/exists-operation-being-ignored-when-searching/33028/4 "2017-07-05T23:42:24Z")

</div>


