例如,假设我们具有以下映射:
{
"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
最佳答案
是的,实际上脚本查询可以解决问题:
GET index_name/location/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
"lang": "painless"
}
}
}
]
}
}
}
谢谢
关于elasticsearch - 在查询Elasticsearch中访问字段文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48693945/