我尝试使用地理位置实施 function_score ,类似于Elastic Search Geo Distance Sort中描述的内容。但是,我的文档geo-location字段位于一个具有嵌套映射的数组中。
{
"mappings": {
"bo_contentmodel": {
"properties": {
"contentId": {
"type": "double"
},
"contentName": {
"type": "string",
"index": "no"
},
"geoInfo": {
"type": "nested",
"properties": {
"geoPhone": {
"type": "string",
"index": "no"
},
"geoTitle": {
"type": "string",
"index": "no"
},
"point": {
"type": "geo_point"
}
}
}
}
}
}
}
执行以下查询时:
{
"from": 0,
"size": 6,
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [{
"filter": {
"nested": {
"query": {
"geo_distance": {
"distance": "800.0m",
"geoInfo.point": {
"lat": 4.654159,
"lon": -74.11392
}
}
},
"path": "geoInfo"
}
},
"gauss": {
"geoInfo.point": {
"origin": {
"lat": 4.654159,
"lon": -74.11392
},
"scale": "0.5km",
"offset": "0.01km"
}
},
"weight": 200
}],
"boost_mode": "replace"
}
}
}
获得以下结果:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1377,
"max_score": 200,
"hits": [{
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "665",
"_score": 200,
"_source": {
"contentId": 665,
"contentName": "BOG - CAL - MED - Gurú - Rosas Don Eloy",
"geoInfo": [{
"point": {
"lat": 4.652946,
"lon": -74.111271
},
"geoPhone": "Carrera 68D #23B - 25 local 7",
"geoTitle": "Rosas Don Eloy"
}, {
"point": {
"lat": 4.61455,
"lon": -74.068151
},
"geoPhone": " Calle 27B #6 - 73 Esquina",
"geoTitle": "Rosas Don Eloy"
}, {
"point": {
"lat": 6.208072,
"lon": -75.567081
},
"geoPhone": "Carrera 37 #8A - 51 El Poblado",
"geoTitle": "Rosas Don Eloy"
}]
}
}, {
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "968",
"_score": 200,
"_source": {
"contentId": 968,
"contentName": "Bogotá - Gurú - Maloka",
"geoInfo": [{
"point": {
"lat": 4.655359,
"lon": -74.109347
},
"geoPhone": "Cra. 68 D # 24 A - 51",
"geoTitle": "Maloka en Bogotá"
}]
}
}, {
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "1328",
"_score": 200,
"_source": {
"contentId": 1328,
"contentName": "PuntoFarma Final",
"geoInfo": [{
"point": {
"lat": 4.710077,
"lon": -74.05901
},
"geoPhone": "Calle 127b # 50A-65",
"geoTitle": "La Cosecha"
}, {
"point": {
"lat": 4.71885,
"lon": -74.035316
},
"geoPhone": "Calle 140 # 11 - 01 Cedritos",
"geoTitle": "Montearroyo 2"
}, {
"point": {
"lat": 4.731724,
"lon": -74.045728
},
"geoPhone": "Calle 150 # 19 A - 06",
"geoTitle": "Las Margaritas"
}, {
"point": {
"lat": 4.618438,
"lon": -74.071008
},
"geoPhone": "Calle 31 # 13A - 51 Torre 2 Local 15",
"geoTitle": "Panorama"
}, {
"point": {
"lat": 4.721164,
"lon": -74.039739
},
"geoPhone": "Carrera 13 No. 140 - 21",
"geoTitle": "Cedritos"
}, {
"point": {
"lat": 4.656416,
"lon": -74.107209
},
"geoPhone": "Carrera 68 D # 25 B - 86 Local 1-17",
"geoTitle": "Torre Central"
}]
}
}, {
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "14",
"_score": 1,
"_source": {
"contentId": 14,
"contentName": "Alumbrado en Medellín 2013",
"geoInfo": []
}
}, {
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "19",
"_score": 1,
"_source": {
"contentId": 19,
"contentName": "Bogotá Despierta Final",
"geoInfo": []
}
}, {
"_index": "contents",
"_type": "bo_contentmodel",
"_id": "22",
"_score": 1,
"_source": {
"contentId": 22,
"contentName": "Pastelería Jacques",
"geoInfo": []
}
}]
}
}
正如您所看到的,前三个文档具有相同的分数(此处为错误)由于地理位置不同,预计分数会发生变化。
它可以吗?,我该如何实现呢?
谢谢!