【问题标题】:Access field document in query elasticsearch在查询elasticsearch中访问字段文档
【发布时间】:2018-02-10 02:16:59
【问题描述】:

例如假设我们有这个映射:

{
    "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 查询中访问字段文档值?

使用 脚本查询 可行吗?文档here

【问题讨论】:

  • 您链接的文档就是这样做的,所以我不明白为什么它不可行..

标签: elasticsearch elasticsearch-5


【解决方案1】:

是的,实际上 脚本查询 可以解决问题:

GET index_name/location/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "script": {
                        "script": {
                            "inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
                            "lang": "painless"
                        }
                    }
                 }
            ]
        }
    }
}

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多