GEO query,对象封装坐标点不能存储

作者 xuewb_1024 | 发布于2018年04月26日 | 阅读数:387

最近用String封装了经纬度坐标点,一切都ok;然后尝试用对象封装;但是存储在es里边的都是对象内存地址,而不是属性值对应的经纬度。我该怎么做?代码如下:
 

  MapLocation locations = new MapLocation(); 
  locations.setLat(116.4072154982);
  locations.setLon(39.9047253699); 
  Map<String, Object> map = new HashMap<>(); 
  String id = "1";
   map.put("name","一号"); 
  map.put("age",18); 
  map.put("locations",locations); 
  map.put("school","中南大学"); 
  String saveDoc = clientUtil.saveDoc("girlfriend", "gf_gentle", id, map);
 
 
这样存储后,es显示的时对象的地址值,而不是类似:
{
“location”:{
       "lat":"116.4072154982",
       "lon":"39.9047253699"
    }
}
我该怎么处理,才可以在es里边展示经纬度数据?
已邀请:

JackGe

赞同来自: xuewb_1024 CarrieJin

XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
                .startObject()
                    .field("name", "一号")
                    .field("age", 18)
                    .field("school", "中南大学")
                    .startObject("locations").field("lat", 116.4072154982)
                            .field("lon", 39.9047253699)
                    .endObject();
prepareBulk.add(client.prepareIndex(index, type).setSource(xContentBuilder));

yayg2008

赞同来自:

PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}

PUT my_index/_doc/1
{
"text": "Geo-point as an object",
"location": {
"lat": 41.12,
"lon": -71.34
}
}

PUT my_index/_doc/2
{
"text": "Geo-point as a string",
"location": "41.12,-71.34"
}

PUT my_index/_doc/3
{
"text": "Geo-point as a geohash",
"location": "drm3btev3e86"
}

PUT my_index/_doc/4
{
"text": "Geo-point as an array",
"location": [ -71.34, 41.12 ]
}

GET my_index/_search
{
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 42,
"lon": -72
},
"bottom_right": {
"lat": 40,
"lon": -74
}
}
}
}
}
支持的格式,详情查看官网https://www.elastic.co/guide/e ... .html

要回复问题请先登录注册