无法使用 Java API 在 ElasticSearch 1.7.3 中为 GeoPoints 编制索引
Unable to index GeoPoints in ElasticSearch 1.7.3 with Java API
我的Class
package be.smartask.data;
import be.smartask.core.api.Language;
import org.elasticsearch.common.geo.GeoPoint;
import java.util.Date;
import java.util.Map;
/**
* @author Glenn Van Schil
* Created on 26/01/2016
*/
public class CityValue extends Value {
private int radius;
private Map<Language, String> translations;
private GeoPoint geoPoint;
private Suggest suggest;
public CityValue() {
}
public CityValue(Date createdOn, String id, Date lastUpdatedOn, String fieldId, String projectId, String userId, GeoPoint geoPoint, int radius, Suggest suggest, Map<Language, String> translations) {
super(createdOn, id, lastUpdatedOn, fieldId, projectId, userId);
this.geoPoint = geoPoint;
this.radius = radius;
this.suggest = suggest;
this.translations = translations;
}
public GeoPoint getGeoPoint() {
return geoPoint;
}
public void setGeoPoint(GeoPoint geoPoint) {
this.geoPoint = geoPoint;
}
public void setGeoPoint(double lat, double lon) {
this.geoPoint = new GeoPoint(lat, lon);
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public Suggest getSuggest() {
return suggest;
}
public void setSuggest(Suggest suggest) {
this.suggest = suggest;
}
public Map<Language, String> getTranslations() {
return translations;
}
public void setTranslations(Map<Language, String> translations) {
this.translations = translations;
}
}
我的映射
{
"cityvalue": {
"dynamic_templates": [{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}],
"properties": {
"createdOn": {
"type": "date",
"format": "date_hour_minute_second"
},
"lastUpdatedOn": {
"type": "date",
"format": "date_hour_minute_second"
},
"suggest": {
"type": "completion",
"preserve_separators": false,
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
},
"geoPoint": {
"type": "geo_point"
}
}
}
}
当我尝试索引该对象时,出现以下错误
org.elasticsearch.ElasticsearchParseException: field must be either lat/lon or geohash
为什么会抛出这个错误,我该如何解决?
我一直使用 Spring-data 与 Elastic 交互,Elastic 也有一个 GeoPoint 对象,它在相同的映射下工作正常,但因为我删除了 Spring-我必须切换的数据
org.springframework.data.elasticsearch.core.geo.GeoPoint 到 org.elasticsearch.common.geo.GeoPoint
我通过不使用 Elastic GeoPoint 对象解决了这个问题。我创建了以下对象并将 Elastic 的 GeoPoint 的所有用法替换为我的对象。
package be.smartask.core.api.data;
/**
* @author Glenn Van Schil
* Created on 20/04/2016
*/
public class GeoPoint {
double lat, lon;
public GeoPoint() {
}
public GeoPoint(double lat, double lon) {
this.lat = lat;
this.lon = lon;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
我的映射没有改变。
我的Class
package be.smartask.data;
import be.smartask.core.api.Language;
import org.elasticsearch.common.geo.GeoPoint;
import java.util.Date;
import java.util.Map;
/**
* @author Glenn Van Schil
* Created on 26/01/2016
*/
public class CityValue extends Value {
private int radius;
private Map<Language, String> translations;
private GeoPoint geoPoint;
private Suggest suggest;
public CityValue() {
}
public CityValue(Date createdOn, String id, Date lastUpdatedOn, String fieldId, String projectId, String userId, GeoPoint geoPoint, int radius, Suggest suggest, Map<Language, String> translations) {
super(createdOn, id, lastUpdatedOn, fieldId, projectId, userId);
this.geoPoint = geoPoint;
this.radius = radius;
this.suggest = suggest;
this.translations = translations;
}
public GeoPoint getGeoPoint() {
return geoPoint;
}
public void setGeoPoint(GeoPoint geoPoint) {
this.geoPoint = geoPoint;
}
public void setGeoPoint(double lat, double lon) {
this.geoPoint = new GeoPoint(lat, lon);
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public Suggest getSuggest() {
return suggest;
}
public void setSuggest(Suggest suggest) {
this.suggest = suggest;
}
public Map<Language, String> getTranslations() {
return translations;
}
public void setTranslations(Map<Language, String> translations) {
this.translations = translations;
}
}
我的映射
{
"cityvalue": {
"dynamic_templates": [{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}],
"properties": {
"createdOn": {
"type": "date",
"format": "date_hour_minute_second"
},
"lastUpdatedOn": {
"type": "date",
"format": "date_hour_minute_second"
},
"suggest": {
"type": "completion",
"preserve_separators": false,
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
},
"geoPoint": {
"type": "geo_point"
}
}
}
}
当我尝试索引该对象时,出现以下错误
org.elasticsearch.ElasticsearchParseException: field must be either lat/lon or geohash
为什么会抛出这个错误,我该如何解决?
我一直使用 Spring-data 与 Elastic 交互,Elastic 也有一个 GeoPoint 对象,它在相同的映射下工作正常,但因为我删除了 Spring-我必须切换的数据 org.springframework.data.elasticsearch.core.geo.GeoPoint 到 org.elasticsearch.common.geo.GeoPoint
我通过不使用 Elastic GeoPoint 对象解决了这个问题。我创建了以下对象并将 Elastic 的 GeoPoint 的所有用法替换为我的对象。
package be.smartask.core.api.data;
/**
* @author Glenn Van Schil
* Created on 20/04/2016
*/
public class GeoPoint {
double lat, lon;
public GeoPoint() {
}
public GeoPoint(double lat, double lon) {
this.lat = lat;
this.lon = lon;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
我的映射没有改变。