我正在尝试使用更新API更新Elastic search 1.7中的文档。 我想更新地理点值。在调用更新API时,我正在尝试更新地理点和字段。我无法在此处更新地理位置。
创建索引:
curl -X PUT "http://localhost:9200/my_index/"
创建映射
curl -X POST -d '{"my_type":
{"properties":
{"id": {"type": "string"},
"status":{"type":"string"},
"location": {"type": "geo_point","lat_lon":true}}}}'
http://localhost:9200/my_index/_mapping/my_type
插入
curl -XPOST -H "Content-Type: application/json" -d '{
"Id": "125",
"status": "LIVE",
"location": {
"lat": 10.4839,
"lon": 10.34904
}}' "http://localhost:8080/{endpoint}"
更新
curl -XPOST -H "Content-Type: application/json" -d '{
"oldUniqueId":"2location9",
"Id": "125",
"status": "LIVE",
"newLocation": {
"lat": 15.4839,
"lon": 15.34904
},
"oldLocation": {
"lat": 10.4839,
"lon": 10.34904
}}' "http://localhost:8080/{endpoint}"
要更新的逻辑(这里我将旧的和新的loc作为数据并尝试更新位置字段)
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("my_index");
updateRequest.type("my_type");
updateRequest.id(myUpdate.Id());
try {
updateRequest.doc(jsonBuilder()
.startObject()
.field("status", "CLOSED")
.field("location",myUpdate.getNewLocation())
.endObject());
} catch (IOException e) {
e.printStackTrace();
}
return myUpdate;
}
在运行时我无法更新位置。我已经在映射中将lat_lon设置为true,并尝试传递" location.lat" = 10.435作为要更新的数据。这增加了一个新字段,但没有更新现有字段。
获得这样的例外:
java.lang.NumberFormatException: For input string:
"Location(lat=15.4839"
! at
sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) ~[na:1.8.0_121]
! at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) ~[na:1.8.0_121]
! at java.lang.Double.parseDouble(Double.java:538) ~[na:1.8.0_121]
! at org.elasticsearch.common.geo.GeoPoint.resetFromString(GeoPoint.java:68) ~[merchant-service-server-0.0.3-SNAPSHOT.jar:0.0.3-SNAPSHOT]
! at org.elasticsearch.index.mapper.geo.GeoPointFieldMapper.parsePointFromString(GeoPointFieldMapper.java:551)