2015-02-16 8 views
3

В настоящее время я обнаружил странный вопрос: когда я сортирую основанный на поле, он выбрасывает исключение: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", 
     "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[email protected]>!]: 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\": [email protected]>!]: 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\": [email protected]>!]: 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\": [email protected]>!]: 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/_search?pretty' -d '{ 
"query": {"match" : {"first_name" : "john"}}}' 
{ 
    "took" : 3, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 4, 
    "max_score" : 0.30685282, 
    "hits" : [ { 
     "_index" : "pb", 
     "_type" : "p", 
     "_id" : "4", 
     "_score" : 0.30685282, 
     "_source":{ 
"first_name" : ["john", "jon"], 
"last_name" : "abcdef", 
"location_size": 3, 
"relative_size": 3, 
"dob_size"  : 1} 
    }, { 
     "_index" : "pb", 
     "_type" : "p", 
     "_id" : "1", 
     "_score" : 0.30685282, 
     "_source":{ 
"first_name" : ["john", "jon"], 
"last_name" : "abcdef", 
"location_size": 5, 
"relative_size": 3, 
"dob_size"  : 1} 
    }, { 
     "_index" : "pb", 
     "_type" : "p", 
     "_id" : "2", 
     "_score" : 0.30685282, 
     "_source":{ 
"first_name" : ["john", "jon"], 
"last_name" : "abcdef", 
"location_size": 5, 
"relative_size": 4, 
"dob_size"  : 0} 
    }, { 
     "_index" : "pb", 
     "_type" : "p", 
     "_id" : "3", 
     "_score" : 0.30685282, 
     "_source":{ 
"first_name" : ["john", "jon"], 
"last_name" : "abcdef", 
"location_size": 5, 
"relative_size": 4, 
"dob_size"  : 1} 
    } ] 
    } 
} 

Я следовал за директивой от here, но кажется, что он не работает.

отображение является:

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, Build: 89d3241/2014-11-26T15: 49: 29Z, JVM: 1.7 .0_55

Любые идеи?

Спасибо!

ответ

5

Это проблема с оболочкой. Вам нужно избегать синг-котировок. Запрос должен выглядеть так:

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" 
    } 
    } 
}' 
+0

Спасибо! вот что я искал. – milodky

Смежные вопросы