Elasticsearch - 访问嵌套变量

时间:2015-03-09 10:58:07

标签: elasticsearch

我想从我的数据中获取坐标。

"userLoc" : {
    "locNm" : "Alexandra Road",
    "coordinates" : [ 
        103.8174926, 
        1.29143
    ],

我尝试了以下方法来获取坐标的第二个值,但它没有成功。

"script": "return _score*doc['userLoc'].coordinates[1];"

出现以下错误。

{
   "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[H94j5eYQRXantctqOKMduw][merchantindex][0]: QueryPhaseExecutionException[[merchantindex][0]: query[function score (_all:test,function=script[return _score*doc['userLoc'].coordinates[1];], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [userLoc] in mapping with types []]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][1]: QueryPhaseExecutionException[[merchantindex][1]: query[function score (_all:test,function=script[return _score*doc['userLoc'].coordinates[1];], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [userLoc] in mapping with types []]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][2]: QueryPhaseExecutionException[[merchantindex][2]: query[function score (_all:test,function=script[return _score*doc['userLoc'].coordinates[1];], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [userLoc] in mapping with types []]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][3]: QueryPhaseExecutionException[[merchantindex][3]: query[function score (_all:test,function=script[return _score*doc['userLoc'].coordinates[1];], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [userLoc] in mapping with types []]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][4]: QueryPhaseExecutionException[[merchantindex][4]: query[function score (_all:test,function=script[return _score*doc['userLoc'].coordinates[1];], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No field found for [userLoc] in mapping with types []]]; }]",
   "status": 500
}

1 个答案:

答案 0 :(得分:1)

根据{{​​3}}

_source.userLoc.coordinates [0]