Filter docs by field exists not working as expected


(Zelfapp) #1

The Source Example you can see below is being returned by a query on "thin". However, you can see in my query that I'm trying to filter docs using the filter exists "sbb" field. With this query, the Source Example should not be returned because it does not have an "sbb" field correct? Where I have gone wrong in my query or mapping?

Mapping:

"mappings": {
 "mymap": {
    "_all": {
       "enabled": false
    },
    "properties": {
       "sbb": {
          "type": "boolean"
       },
       "sku": {
          "type": "string",
          "analyzer": "full_name",
          "fields": {
             "exact": {
                "type": "string",
                "index": "not_analyzed"
             },
             "partial": {
                "type": "string",
                "index_analyzer": "partial_name",
                "search_analyzer": "full_name"
             }
          }
       },
       "title": {
          "type": "string",
          "analyzer": "full_name",
          "fields": {
             "partial": {
                "type": "string",
                "index_analyzer": "partial_name",
                "search_analyzer": "full_name"
             },
             "sortable": {
                "type": "string",
                "analyzer": "sortable"
             }
          }
       }
    }
 }
}

Query:

"query":{
    "filtered":{
      "query":{
        "bool":{
          "should":[
            {
              "match":{
                "title":{
                  "query":"thin",
                  "operator":"and",
                  "boost":5,
                  "fuzziness":"0"
                }
              }
            },
            {
              "match":{
                "title":{
                  "query":"thin",
                  "boost":2,
                  "fuzziness":"AUTO"
                }
              }
            }
          ]
        }
      },
      "filter": {
        "exists": {
          "field": "sbb"
        }
      }
    }
}

Source Example:

"_source": {
   "title": "Mexican Service Medal Thin Ribbon",
   "tags": [
      "EZR",
      "ISP_IGNORE_PRODUCT_TAG",
      "sbb?_w=50&h=14",
      "SBB_Awards",
      "Thin Ribbon"
   ]
}

(Zelfapp) #2

Any ideas here? I changed the sbb field from boolean, to a string, and that seems to have helped a bit, but I still get results with "thin" in the title on docs where the "sbb" field does not exist. On the https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html exists docs, it states, if the field referenced in the "exists" is "missing completely" then those docs would not be a match.

So again, what am I missing here? Why am I getting documents where the "sbb" field is missing completely?


(system) #3