Overpass "not equal" operator for values

During development I came across a peculiarity that I frankly don’t understand:

When creating an overpass query with the not equal operator for a value, it matches all elements that are tagged with the respective key and but not this value (so far so good) AND all elements that are not tagged with this key.

According to https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide this is intended behaviour.

Now, if I wanted all elements not tagged with a key, I would intuitively use the “not equals” operator on the key, which is supported and does work.

So does anyone know why not equalling a value also includes elements not tagged with the key of this comparison?

Thanks!

What elements do you want to get? If you ask for e.g. highway not equal residential you probably want all highways excluding those with hw=resdidential? In this case you have to use something like highway=* and highway!=residential.

Yes, thanks, I figured that out. I was just wondering why the “key != value” includes all elements that do not match the key.

I think most programs follow this logic.
Example: When I search for “highway=* and area!=yes” I want to get highways which do not have an area tag or those where this tag is not equal to “yes”. I would be very surprised to get only those highways which also have an area tag.