How to access document fields from script?

Hi

I am trying to access document fields in the script based sorting

curl -XPOST 'http://localhost:9200/users/user/_search' -d '{
"query" : { "term" : { "group" : "dpe" }},
"sort" : { "_script" : { "script" : "doc['first_name'].stringValue",
"type" : "string", "order" : "asc"}}
}'

and I get following exception

nested: ElasticSearchIllegalArgumentException[No field found for
[org.elasticsearch.index.field.data.strings.StringDocFieldData@2ad6d4be]]

I get this error if I try to accessing document fields using
doc['field_name'].stringValue. I am able to access values by using
doc.field_name syntax though.

Thanks
Harish

Its because of curl and the use of ' (which is used after -d as well).

On Tue, Jan 10, 2012 at 12:37 AM, Harish Rawat harish@groupon.com wrote:

Hi

I am trying to access document fields in the script based sorting

curl -XPOST 'http://localhost:9200/users/user/_search' -d '{
"query" : { "term" : { "group" : "dpe" }},
"sort" : { "_script" : { "script" : "doc['first_name'].stringValue",
"type" : "string", "order" : "asc"}}
}'

and I get following exception

nested: ElasticSearchIllegalArgumentException[No field found for
[org.elasticsearch.index.field.data.strings.StringDocFieldData@2ad6d4be]]

I get this error if I try to accessing document fields using
doc['field_name'].stringValue. I am able to access values by using
doc.field_name syntax though.

Thanks
Harish