Home > Net >  Illegal Argument Exception in Elasticsearch 7.10.1 when Loading data
Illegal Argument Exception in Elasticsearch 7.10.1 when Loading data

Time:01-26

I'm getting an error when I try to load data into an index I created with a mapping. Here is what I have done:

I have created an index with a mapping using the following command to an ElasticSearch (version 7.10.1) running in a docker container:

curl -sS -H "Content-Type: application/json" -XPUT localhost:9200/test_write_v1?pretty -d {
    "settings" : {
        "index" : {
            "number_of_shards" : 1, 
            "number_of_replicas" : 0
        }
    },
    "mappings": {
        "properties": {
            "id": {
                "type": "text",
                "fields": {
                    "raw": {
                        "type": "keyword"
                    }
                }
            },
            "created": {
                "type": "date"
            },
            "startAltitudeMeters": {
                "type": "float"
            },
            "startLocationPoint": {
                "type": "geo_point"
            }
        }
    }
}

However when I try to load in the test JSON using:

curl -sS -H "Content-Type: application/json" -XPOST localhost:9200/test_write_v1/test?pretty -d {
    "id": "000f4930-b168-3560-b691-78e757524494",
    "created": "2021-09-15T18:26:43.713Z",
    "startLocationPoint": {
        "lat": 34.803279,
        "lon": -119.633169
    },
    "startAltitudeMeters": 30000.0
}

I get the error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "can't merge a non object mapping [startLocationPoint] with an object mapping"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "can't merge a non object mapping [startLocationPoint] with an object mapping"
  },
  "status" : 400
}

From my research it looks like Elasticsearch should be able to understand GeoPoints with a lat, lon. It also looks to me like my mapping is correct.

Did I make the index incorrectly? Is the mapping wrong? Why am I seeing this error?

CodePudding user response:

The problem is highlighted below

curl -sS -H "Content-Type: application/json" -XPOST localhost:9200/test_write_v1/test?pretty -d {
                                                                                  ^
                                                                                  |
                                                                      this should be _doc

Basically, you're creating a default mapping (i.e. for the _doc type) and then you're indexing a document into a specific type called test which doesn't use your default mapping. You should not do that.

  •  Tags:  
  • Related