Sorting 使用脚本的elasticsearch排序错误
目前我遇到了一个奇怪的问题:当我根据字段排序时,它抛出一个异常:Sorting 使用脚本的elasticsearch排序错误,sorting,
elasticsearch,Sorting,
elasticsearch,目前我遇到了一个奇怪的问题:当我根据字段排序时,它抛出一个异常: curl -XGET 'http://localhost:9200/pb/p/_search?pretty' -d '{ "query": {"match" : {"first_name" : "john"}}, "sort" : { "_script" : { "script" : "doc['dob_size'].value * factor1", "type" : "number",
curl -XGET 'http://localhost:9200/pb/p/_search?pretty' -d '{
"query": {"match" : {"first_name" : "john"}},
"sort" : {
"_script" : {
"script" : "doc['dob_size'].value * factor1",
"type" : "number",
"params" : {"factor1" : 1},
"order" : "desc"
}}}'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 1,
"failed" : 4,
"failures" : [ {
"index" : "pb",
"shard" : 0,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[pb][0]: query[filtered(first_name:john)->cache(_type:p)],from[0],size[10],sort[<custom:\"_script\": org.elasticsearch.search.sort.ScriptSortParser$2@7ac5f844>!]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: dob_size for class: Script132]]; "
}, {
"index" : "pb",
"shard" : 2,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[pb][2]: query[filtered(first_name:john)->cache(_type:p)],from[0],size[10],sort[<custom:\"_script\": org.elasticsearch.search.sort.ScriptSortParser$2@12127900>!]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: dob_size for class: Script132]]; "
}, {
"index" : "pb",
"shard" : 3,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[pb][3]: query[filtered(first_name:john)->cache(_type:p)],from[0],size[10],sort[<custom:\"_script\": org.elasticsearch.search.sort.ScriptSortParser$2@5b2e7754>!]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: dob_size for class: Script132]]; "
}, {
"index" : "pb",
"shard" : 4,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[pb][4]: query[filtered(first_name:john)->cache(_type:p)],from[0],size[10],sort[<custom:\"_script\": org.elasticsearch.search.sort.ScriptSortParser$2@5dd9cdc1>!]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: dob_size for class: Script132]]; "
} ]
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
我遵循了来自的指南,但似乎不起作用
映射为:
curl -XGET 'http://localhost:9200/pb/p/_mapping?pretty'
{
"pb" : {
"mappings" : {
"p" : {
"properties" : {
"dob_size" : {
"type" : "integer"
},
"first_name" : {
"type" : "string",
"index" : "not_analyzed"
},
"last_name" : {
"type" : "string",
"index" : "not_analyzed"
},
"location_size" : {
"type" : "integer"
},
"relative_size" : {
"type" : "integer"
}
}
}
}
}
}
elasticsearch的版本是:./elasticsearch-v
版本:1.4.1,内部版本:89d3241/2014-11-26T15:49:29Z,JVM:1.7.055
有什么想法吗
谢谢 这是shell的一个问题。你需要避开单引号。 查询应类似于-
curl -XPOST 'http://localhost:9200/pb/p/_search' -d '{
"query": {
"match": {
"first_name": "john"
}
},
"sort": {
"_script": {
"script": "doc['"'"'dob_size'"'"'].value * factor1",
"type": "number",
"params": {
"factor1": 1
},
"order": "desc"
}
}
}'
谢谢这就是我要找的。
curl -XPOST 'http://localhost:9200/pb/p/_search' -d '{
"query": {
"match": {
"first_name": "john"
}
},
"sort": {
"_script": {
"script": "doc['"'"'dob_size'"'"'].value * factor1",
"type": "number",
"params": {
"factor1": 1
},
"order": "desc"
}
}
}'