I'm using NodeJS ElasticSearch with ElasticSearch 7.0. I create mapping geo_point type on specific field, but it doesn't show geo_point type in _mapping. I tried to search using filter.geo_distance, I got failed to find geo point field.

Node ElasticSearch Mapping

client.indices.putMapping({
  index: 'listing',
  type: 'detail',
  body: {
    properties: {
      'listing_coordinates': {
        "type": "geo_point"
      }
    }
  }
}, function(err) { console.log(err) })

Mapping Error

[illegal_argument_exception] Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.

/listing/_mapping

mappings: {
 properties: {
  "listing_coordinates": {
    "properties": {
      "lat": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "lon": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  },
 }
}

Node Search

client.search({
    index: 'listing',
    type: 'detail',
    size: 5,
    body: {
      query : {
        "bool": {
          "filter": {
            "geo_distance" : {
              "distance" : "500km",
              "listing_coordinates" : {
                "lat" : 3.0567521,
                "lon" : 101.5854671
              }
            }
          }
        }
      }
    }
 }

Search error

[query_shard_exception] failed to find geo_point field [listing_coordinates]

I had mapping dates fields on my listing, it worked well.

1 Answers

1
Fei On Best Solutions

See this: https://github.com/elastic/elasticsearch-js/issues/166 I think your problem should be similar to his. Please pay attention to the order of event execution. Also note that if you did not wait for PutMapping to be finished, then those index might be created automatically into text fields.

Update:

It seemed that your PutMapping failed and then your mapping is created into text field by receiving data as default behavior.

In ES7.0, you cannot provide type when creating an index unless setting include_type_name. In your case, type is detail. To handle include_type_name, see this. Or you could just try to remove type: detail in your case. Please try to clear your index mapping before trying.

Ref: https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html#removal-of-types