Search code examples
elasticsearchlucenekibana

ElasticSearch/Lucene query string — select "field X exists"


How do I query ElasticSearch through Kibana to select items that have field X?

For example, I have a mapping with fields {"a": {"type": "string"}, "b": {"type": "string"}}, and two documents

{"a": "lalala"}
{"a": "enoheo", "b": "nthtnhnt"}

I want to find the second document without knowing what its b actually is.


Solution

  • Use the exists filter, like:

    POST /test_index/_search
    {
        "filter": {
            "exists": {
               "field": "b"
            }
        }
    }
    

    EDIT: If you need a Lucene query-string query, this should do it:

    POST /test_index/_search
    {
       "query": {
          "query_string": {
             "query": "b:*"
          }
       }
    }
    

    Here is some code I used to test it:

    http://sense.qbox.io/gist/ad336a0888a279bfdace03e217bf1915adbf0fe2