Retrieve document where certain field exists

Hi,

I'm trying to find documents in which certain field exist using POST. Here is the code snippet that I'm using. For example, I would like to find all the documents in which "activity_name" field is present.

> {
>   "query": {
>     "filtered": {
>       "query": {
>         "bool": {
>           "should": [
>             {
>               "query_string": {
>                 "query": "type:\"help-me\""
>               }
>             }
>           ]
>         }
>       },
>       "filter": {
>         "bool": {
>           "must": [
>             {
>                 "exists": {
>                     "field": "activity_name"
>                 }            
>             }
>           ]
>         }
>       } 
>     } 
>   },
>   "size": 5  
> }

The above code doesn't return any hits. Is this the right way to do it or am I missing something here?

Regards,
Bharath

Maybe simplify the filter

{
    query: {
        match_all: {}
    },
    filter : {
        exists : { "field" : "activity_name" }
    }
}

But this would mean, it will find all the documents which has activity_name field irrespective of the 'type' right?

Yes, this was just an example for the filter, you can change the query part.

It worked. Thanks