elasticsearch,spring-boot,Java,elasticsearch,Spring Boot" /> elasticsearch,spring-boot,Java,elasticsearch,Spring Boot" />

Java elasticsearch按从近到远的距离排列的地理搜索顺序

Java elasticsearch按从近到远的距离排列的地理搜索顺序,java,elasticsearch,spring-boot,Java,elasticsearch,Spring Boot,映射地址属性:id名称类型和位置。 搜索映射: { "address": { "properties": { "id": { "type": "long" }, "type": { "type": "long" }, "name": { "type": "string" }, "location": { "type": "geo_poin

映射
地址
属性:
id
名称类型和
位置
。 搜索映射:

{
  "address": {
    "properties": {
      "id": {
        "type": "long"
      },
      "type": {
        "type": "long"
      },
      "name": {
        "type": "string"
      },
      "location": {
        "type": "geo_point"
      }
    }
  }
}
搜索命令(过滤器
address.type=1
distance=100km
):


我想搜索地址匹配
type=1
和地理
distance=100km
;我想得到的结果是,
按距离排序ASC
。如何解决这个问题?

因为您是基于距离排序的,所以我将匹配查询移动到布尔过滤器中

这应该行得通

{
    "query": {
        "bool": {
            "must": [{
                    "geo_distance": {
                        "distance": "1000000km",
                        "location": {
                            "lat": 24.46667,
                            "lon": 118.1
                        }
                    }
                },
                {
                    "term": {
                        "type": {
                            "value": 1
                        }
                    }
                }
            ]
        }
    },
    "sort": {
        "_geo_distance": {
            "location": "24.46667,118.1",
            "order": "asc"
        }
    }
}
{
    "query": {
        "bool": {
            "must": [{
                    "geo_distance": {
                        "distance": "1000000km",
                        "location": {
                            "lat": 24.46667,
                            "lon": 118.1
                        }
                    }
                },
                {
                    "term": {
                        "type": {
                            "value": 1
                        }
                    }
                }
            ]
        }
    },
    "sort": {
        "_geo_distance": {
            "location": "24.46667,118.1",
            "order": "asc"
        }
    }
}