Search code examples
elasticsearchelastic-stacklogstash-configuration

Mapping longitude and latitude from .csv data to geo_point type not working


This is the fourth time I attempt to do these mapping. But I do not hav my previous configuration files.

classes2.conf

    input {
  file {

    path => "D:\Workspace.Elastic\FinalVersions\classes.csv"    
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}

filter {

    csv {
        columns => ["TITLE","PROFFESSOR","MAJOR","SEMESTER","student_count","unit","rating","submit_date","latitude","longitude"]
        separator => ","


    }   

    mutate {
        convert => { "longitude" => "float" }
        convert => { "latitude" => "float" }
        rename => {
            "longitude" => "[location][lon]"
            "latitude" => "[location][lat]"
        }
    }
}

output {
    stdout { codec => rubydebug }
    elasticsearch {
        hosts => "localhost:9200"
        index => "geopointest"
    }
}

classesRating_mapping2.json

{
  "class": {
    "properties": {

      "location": {
        "type": "geo_point"
      }
    }
  }
}

I get the following error:

[location] is defined as an object in mapping [doc] but this name is already used for a field in other types"

I have created geopointest index and added the json mapping like this:

curl  -X PUT -H "Content-Type: application/json" http://localhost:9200/geopointest/class/_mapping --data-binary @classesRating_mapping2.json

What am I missing? Many thanks.


Solution

  • The problem is that in your mapping you're using class which is a custom type name. That means you need to modify your elasticsearch output like this:

    elasticsearch {
        hosts => "localhost:9200"
        index => "geopointest"
        document_type => "class"        <-- add this line
    }
    

    Without that line, Logstash uses the log type name and that was the reason why your mapping was off.