Hi,
I am experiencing script_fields issue. Below is a shell script with curl
examples. In short: I prepare an index, index three objects into it, verify
that I can query objects from index and that I can extract values of
particular "fields" (though script_fields does not require fields being
stored) and then use a script_fields query which fails. Not sure what is
wrong:
The following is my shell script:
#!/bin/sh
echo Index setup
curl -XDELETE 'http://localhost:9200/foo/'
curl -XPUT 'http://localhost:9200/foo/' -d '{ index : { number_of_shards :
1, number_of_replicas : 0 }}'
curl -XPUT 'http://localhost:9200/foo/bar/_mapping' -d '
{ "bar" : {
"properties" : {
"date" : { "type" : "date", "store" : "yes" },
"string" : { "type" : "string", "store" : "yes", "index" :
"not_analyzed" }
}
}}'
curl -XGET 'http://localhost:9200/foo/bar/_mapping?pretty=1'
echo
echo Indexing
curl -XPUT 'http://localhost:9200/foo/bar/1' -d
'{"date":"2010-01-01","string":"one"}'
curl -XPUT 'http://localhost:9200/foo/bar/2' -d
'{"date":"2010-01-02","string":"two"}'
curl -XPUT 'http://localhost:9200/foo/bar/3' -d
'{"date":"2010-01-03","string":"three"}'
curl -XPOST 'http://localhost:9200/foo/_refresh'
echo
echo Search
curl -XGET 'http://localhost:9200/foo/bar/_search?pretty=1' -d '
{
"from" : 0, "size" : 1,
"fields" : ["date","string"],
"query" : { "match_all" : { } }
}'
echo
echo Search with script_fields
echo
curl -XGET 'http://localhost:9200/foo/bar/_search?pretty=1' -d '
{
"from" : 0, "size" : 1,
"fields" : ["date","string"],
"query" : { "match_all" : { } },
"script_fields" : {
"test1" : { "script" : "doc['date'].date.millis" },
"test2" : { "script" : "doc['string'].stringValue" }
}
}'
echo
The following is output:
Index setup
{"ok":true,"acknowledged":true}{"ok":true,"acknowledged":true}{"ok":true,"acknowledged":true}{
"foo" : {
"bar" : {
"_boost" : {
"name" : "_boost"
},
"dynamic" : true,
"enabled" : true,
"date_formats" : [ "dateOptionalTime", "yyyy/MM/dd
HH:mm:ss||yyyy/MM/dd" ],
"_source" : {
"enabled" : true,
"name" : "_source"
},
"_id" : {
"store" : "no"
},
"path" : "full",
"properties" : {
"string" : {
"omit_term_freq_and_positions" : false,
"index_name" : "string",
"index" : "not_analyzed",
"omit_norms" : false,
"store" : "yes",
"boost" : 1.0,
"term_vector" : "no",
"type" : "string"
},
"date" : {
"omit_term_freq_and_positions" : true,
"index_name" : "date",
"index" : "not_analyzed",
"omit_norms" : true,
"store" : "yes",
"boost" : 1.0,
"format" : "dateOptionalTime",
"precision_step" : 4,
"term_vector" : "no",
"type" : "date"
}
},
"_all" : {
"enabled" : true,
"store" : "no",
"term_vector" : "no"
},
"type" : "object"
}
}
}
Indexing
{"ok":true,"_index":"foo","_type":"bar","_id":"1"}{"ok":true,"_index":"foo","_type":"bar","_id":"2"}{"ok":true,"_index":"foo","_type":"bar","_id":"3"}{"ok":true,"_shards":{"total":1,"successful":1,"failed":0}}
Search
{
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "foo",
"_type" : "bar",
"_id" : "1",
"_score" : 1.0,
"fields" : {
"date" : "2010-01-01T00:00:00.000Z",
"string" : "one"
}
} ]
}
}
Search with script_fields
{
"_shards" : {
"total" : 1,
"successful" : 0,
"failed" : 1,
"failures" : [ {
"reason" : "CompileException[[Error: null]\n[Near : {... Unknown
....}]\n ^\n[Line: 1, Column: 0]]; nested: "
} ]
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ ]
}
}
And the following is what I see in server node log:
[11:45:12,773][INFO ][cluster.metadata ] [Starshine] [foo] deleting
index
[11:45:12,818][INFO ][cluster.metadata ] [Starshine] [foo] creating
index, cause [api], shards [1]/[0], mappings []
[11:45:12,994][INFO ][cluster.metadata ] [Starshine] [foo]
create_mapping [bar]
[11:45:13,109][DEBUG][action.search.type ] [Starshine] [13] Failed to
execute fetch phase
[Error: null]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:402)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:152)
at
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:63)
at
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:139)
at
org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:37)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:655)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:332)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:152)
at
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:63)
at
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:139)
at org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
at org.elasticsearch.common.mvel2.MVEL.executeExpression(MVEL.java:1053)
at org.elasticsearch.script.ScriptService.execute(ScriptService.java:77)
at
org.elasticsearch.index.field.function.script.ScriptFieldsFunction.execute(ScriptFieldsFunction.java:79)
at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:136)
at
org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:265)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:309)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.executeFetch(TransportSearchQueryThenFetchAction.java:141)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.access$200(TransportSearchQueryThenFetchAction.java:60)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.run(TransportSearchQueryThenFetchAction.java:114)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.UnsupportedOperationException
at
org.elasticsearch.index.field.function.script.ScriptFieldsFunction.containsKey(ScriptFieldsFunction.java:112)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:545)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:326)
... 23 more
Should I open an issue?
Regards,
Lukas