Hi,
I am using ES 7.2.1 to store large amount of location based data and querying for near-by locations.
For location coordinates, I am using GeoPoint
fields from my java codebase.
ES: 7.2.1
Spring Data Elasticsearch: 4.0.0.DATAES-690-SNAPSHOT
org.elasticsearch: 7.2.1
Template:
curl -X PUT "localhost:9200/_template/store_locator_template?pretty" -H 'Content-Type: application/json' -d'
{
"order": 1,
"index_patterns": [
"store_locator_*"
],
"settings": {
},
"mappings": {
"properties": {
"esId": {
"type": "keyword"
},
"geoPoint": {
"type": "geo_point"
},
"storeName": {
"type": "keyword"
}
}
}
}
Entity class:
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "esId", callSuper = false)
@NoArgsConstructor
@Document(indexName = "store_locator_index", replicas = 0, createIndex = false)
public class EsEntity {
@Id
@Field(type = FieldType.Text)
private String esId;
@GeoPointField
private GeoPoint geoPoint;
@Field(type = FieldType.Text)
private String storeName;
}
And the code to PUT mapping from Spring:
//clazz -> entity class with @Document annotation
boolean indexCreated = false;
if (!elasticsearchOperations.indexExists(clazz)) {
indexCreated = elasticsearchOperations.createIndex(clazz);
}
if (indexCreated) {
elasticsearchOperations.refresh(clazz);
elasticsearchOperations.putMapping(clazz); --> Does the MAGIC
}
When trying to insert data via bulkIndex(), I am getting this error:
org.springframework.data.elasticsearch.ElasticsearchException: Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [{QObQeXEBqxAg6uMFyeNZ=ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=**mapper [geoPoint] of different type, current_type [geo_point], merged_type [ObjectMapper]]]**}]
Also.......
Everything seems to be working for:
ES 6.4.3
Spring Data Elasticsearch 3.1.X
I am able to put mapping (via template) and insert document with GeoPoint.
The index is generated automatically when doc is inserted via code.
Here's my template:
curl -X PUT "localhost:9200/_template/store_locator_template?pretty" -H 'Content-Type: application/json' -d'
{
"order": 1,
"index_patterns": [
"store_locator_*"
],
"settings": {
},
"mappings": {
"store_locator_index": {
"properties": {
"esId": {
"type": "keyword"
},
"geoPoint": {
"type": "geo_point"
},
"storeName": {
"type": "keyword"
}
}
}
}
}
Here's the mapping:
{
"mapping": {
"properties": {
"esId": {
"type": "keyword"
},
"geoPoint": {
"type": "geo_point"
}
}
}
}