例如,假设我们有这样的映射:
{
"location":{
"dynamic":"false",
"properties":{
"locality":{"type":"text"},
"country":{"type":"text"},
"postalCode":{"type":"text"},
"coordinates":{"type":"geo_point"},
"radius":{"type":"double"}
}
}
}
这是我的疑问:
GET index_name/location/_search
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"coordinates": [
2.352222,
48.999
],
"distance": $radius <--- *(here I want to access the
value of radius in document)*
}
}
}
}
}
在Elasticsearch查询中是否存在访问字段文档值的意思?
使用脚本查询是否可行? doc here
答案 0 :(得分:1)
是的,实际上脚本查询可以解决问题:
GET index_name/location/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
"lang": "painless"
}
}
}
]
}
}
}
谢谢