[求助]有人懂elasticSearch么? 希望有前辈踩过这个坑, 我技穷了

我把查询语句写成类似这种形式:

{
    "fields": [
        "_source._id"
    ],
    "from": 0,
    "query": {
        "function_score": {
            "functions": [
            ],
            "query": {
                "filtered": {
                    "filter": {
                        "and": [
                            {
                                "exists": {
                                    "field": "index.gps"
                                }
                            }
                        ]
                    },
                    "query": {
                        "match_all": {}
                    }
                }
            },
            "score_mode": "multiply"
        }
    },
    "script_fields": {
        "distance": {
            "params": {
                "lat": 39.990663,
                "lon": 116.327678
            },
            "script": "doc['index'].empty ? 0 : doc.index['gps'].distanceInKm(lat, lon)"
        }
    },
    "size": 20
}

报错:

{
    "index": "****",
    "shard": 0,
    "status": 400,
    "reason": "GroovyScriptExecutionException[MissingPropertyException[No such property: index for class: Script61]]"
   }

或者写成这样:

    "script_fields": {
        "distance": {
            "params": {
                "lat": 39.990663,
                "lon": 116.327678
            },
            "script": "doc.index['gps'].distanceInKm(lat, lon)"
        }
    }

报错:

{
    "index": "****",
    "shard": 0,
    "status": 400,
    "reason": "GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [index] in mapping with types [program]]]"
   },

有前辈踩过这坑并且爬出来么?

共 1 个回复


zykzhang

这是mapping:

# 0