title: Elasticsearch "failed to find geo_point field [location]" when the mapping is there for that field
body: <p>I have an index with the following mapping:</p>
  
  <pre><code>{
    "mappings":{
      "my_stuff_type":{
        "properties":{
          "location": {
            "type": "geo_point",
            "null_value": -1
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>I have to use the property <code>null_value</code> because some of my documents don't have information about their location (latitude/longitude), but I still would like to search by distance on a location, cf. here: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html</a></p>
  
  <p>When checking the index mapping details, I can verify that the geo mapping is there:</p>
  
  <pre><code>curl -XGET http://localhost:9200/my_stuff_index/_mapping | jq '.my_stuff_index.mappings.my_stuff_type.properties.location'
  {
    "properties": {
      "lat": {
        "type": "float"
      },
      "lon": {
        "type": "float"
      }
    }
  }
  </code></pre>
  
  <p>However when trying to search for documents on that index using a geo distance filter (cf. <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html</a>), then I see this:</p>
  
  <pre><code>curl -XPOST http://localhost:9200/my_stuff_index/_search -d'
  {
    "query": {
      "bool": {
        "filter": {
          "geo_distance": {
            "location": {
              "lat": &lt;PUT_LATITUDE_FLOAT_HERE&gt;,
              "lon": &lt;PUT_LONGITUDE_FLOAT_HERE&gt;
            },
            "distance": "200m"
          }
        }
      }
    }
  }' | jq
  
  {
    "error": {
      "root_cause": [
        {
          "type": "query_shard_exception",
          "reason": "failed to find geo_point field [location]",
          "index_uuid": "mO94yEsHQseQDFPkHjM6tA",
          "index": "my_stuff_index"
        }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
        {
          "shard": 0,
          "index": "my_stuff_index",
          "node": "MDueSn31TS2z0Lamo64zbw",
          "reason": {
            "type": "query_shard_exception",
            "reason": "failed to find geo_point field [location]",
            "index_uuid": "mO94yEsHQseQDFPkHjM6tA",
            "index": "my_stuff_index"
          }
        }
      ],
      "caused_by": {
        "type": "query_shard_exception",
        "reason": "failed to find geo_point field [location]",
        "index_uuid": "mO94yEsHQseQDFPkHjM6tA",
        "index": "my_stuff_index"
      }
    },
    "status": 400
  }
  </code></pre>
  
  <p>I think the <code>null_value</code> property should allow me to insert documents without that <code>location</code> filed and at the same time I should be able to search with filters on that same "optional" field.</p>
  
  <p>Why I am not able to filter on that "optional" field? How could I do this?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>To reproduce this issue with python run the following code snippet, before performing the <code>curl</code>/<code>jq</code> operations from the command line.</p>
  
  <p>The python code depends on this: <code>pip install elasticsearch==5.4.0</code>.</p>
  
  <pre><code>from elasticsearch import Elasticsearch
  from elasticsearch import helpers
  
  my_docs = [
      {"xyz": "foo", "location": {"lat": 0.0, "lon": 0.0}},
      {"xyz": "bar", "location": {"lat": 50.0, "lon": 50.0}}
  ]
  
  es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
  
  index_mapping = '''
  {
    "mappings":{
      "my_stuff_type":{
        "properties":{
          "location": {
            "type": "geo_point",
            "null_value": -1.0
          }
        }
      }
    }
  }'''
  
  es.indices.create(index='my_stuff_index', ignore=400, body=index_mapping)
  
  helpers.bulk(es, my_docs, index='my_stuff_index', doc_type='my_stuff_type')
  </code></pre>