Rick van Lieshout
Rick van Lieshout

Reputation: 2316

Using a geo_point field returns a "mixing up field types" during document insertion

I'm trying to follow the documentation for geo_points. To do this I created an index named "cities"

curl -X POST -H "Cache-Control: no-cache" -H -d '{
  "mappings": {
    "cities": {
      "properties": {
        "name": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "location":{
          "type": "geo_point"
        }

      }
    }
  }
}' "http://192.168.0.76:9200/cities"

I'm now trying to insert a document using the following request:

curl -X POST -H "Cache-Control: no-cache" -d '{
  "name": "Amsterdam",
  "location": "52.3702,4.8952"
}' "http://192.168.0.76:9200/cities/properties?pretty"

This however returns the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location"
    }
  },
  "status": 400
}

Which, to me, seems weird because the documentation states I should be able to insert a document using string notation:

With the location field defined as a geo_point, we can proceed to index documents containing latitude/longitude pairs, which can be formatted as strings, arrays, or objects:

A string representation, with "lat,lon".

What am I doing wrong?

Upvotes: 0

Views: 206

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

There is an error in insertion. You are accidently inserting into different mapping type properties instead of cities . From the documentation fields with same name in different mapping types must have same mapping

This will work

curl -X POST -H "Cache-Control: no-cache" -d '{
  "name": "Amsterdam",
  "location": "52.3702,4.8952"
}' "http://192.168.0.76:9200/cities/cities?pretty"

Upvotes: 1

Related Questions