I want to create index in ElasticSearch with configuration. I want to use geo distance query in elasticSearch
I have a java class and I am using GeoPoint object that ElasticSearch has and which is from: org.elasticsearch.common.geo.GeoPoint;
@Data
@EqualsAndHashCode(callSuper = false)
public class GeofenceDocument extends AbstractBaseDocument {
@Id
private String id;
private Double radius;
private GeoPoint location;
private String geofenceName;
private Set<String> pushIds;
}
I am inserting this class exactly as it is using my java IndexRequest. I am looking from kibana and see my location result as
"location": {
"properties": {
"geohash": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
},
I dont want "type" : "keyword", I want "type" : "geo_point" so ElasticSearch can query within given latitude and longitude.
I don't want this because, in order to use geo query I need to configure like this:
In below configure, I did it manually from kibana
PUT myindex
{
"mappings": {
"_doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
When I configure like this, and if I inspect this index
"mappings": {
"_doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
},
So I did this, I configure it manually and tried to insert my java classes it gives me error:
[type=illegal_argument_exception, reason=[location] is defined as an object in mapping [geofence] but this name is already used for a field in other types]]]
So types are mismatching. If I can configure and then insert java documents into my index it would be great, but I could not configure.
Basically I want to configure just fine to use geo query in ES. I can not directly insert because type is not going to be geo_point. Or may be there will be some way?
Thanks for reading my issue
Update 2:
Now I am getting
[0]: index [geofence-whitelabe], type [geofence], id [1b7ce54c-5001-11e9-a4d2-35bbed2fa815], message [ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse]]; nested: ElasticsearchException[Elasticsearch exception [type=parse_exception, reason=field must be either lat/lon or geohash]];]
after configuring
PUT geofence-whitelabe
{
"mappings": {
"geofence": {
"properties": {
"ca": {
"type": "date"
},
"del": {
"type": "boolean"
},
"geofenceId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"geofenceName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"la": {
"type": "date"
},
"location": {
"type": "geo_point"
},
"radius": {
"type": "float"
}
}
}
}
}