Elasticsearch Play framework plugin


(David-3) #1

I also posted this in the play framework group but maybe somebody here has
also come across this while using elasticsearch with the Play framework.

I ran into this issue when using the elasticsearch plugin for the Play
framework. The elasticsearch index contains a string value for the enum *ClassName.type
*
and the field mapper for the elasticsearch plugin cannot create a new enum
type with the string returned from the index. I also embedded the enum but
the enum could not be instantiated (see error below). It's a very specific
area of Play but has anyone come across this before or know if enum types
can be embedded or even a workaround to allow the mapper to map a string to
an enum type.

Error when trying to map a string as an enum value
ERROR ~
java.lang.IllegalArgumentException: Can not set models.ClassName$EnumName
field models.ClassName.type to java.lang.String
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown
Source)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown
Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at
play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:419)
at
play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:397)
at
play.modules.elasticsearch.mapping.impl.SimpleFieldMapper.inflate(SimpleFieldMapper.java:50)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:161)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:156)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:29)
at
play.modules.elasticsearch.transformer.MapperTransformer.toSearchResults(MapperTransformer.java:75)
at play.modules.elasticsearch.Query.fetch(Query.java:188)
at controllers.Search$ObjectType.findPagewitFilter(Search.java:1545)
at controllers.Search.getCountForFilterMenuItem(Search.java:449)
at controllers.Search.search(Search.java:229)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
at play.Invoker$Invocation.run(Invoker.java:278)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown
Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Error when embedding an enum and trying to retrieve the value as an enum
type.
@6b6jpgfp4
Internal Server Error (500) for request GET /productsearch/search

Execution exception (In /app/controllers/Search.java around line 1545)
RuntimeException occured : Cannot instantiate class
models.CoreAsset$AssetType

play.exceptions.JavaExecutionException: Cannot instantiate class
models.CoreAsset$AssetType
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: Cannot instantiate class
models.CoreAsset$AssetType
at
play.modules.elasticsearch.util.ReflectionUtil.newInstance(ReflectionUtil.java:270)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:153)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:161)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:156)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:29)
at
play.modules.elasticsearch.transformer.MapperTransformer.toSearchResults(MapperTransformer.java:75)
at play.modules.elasticsearch.Query.fetch(Query.java:188)
at controllers.Search$ObjectType.findPagewitFilter(Search.java:1545)
at controllers.Search.getCountForFilterMenuItem(Search.java:410)
at controllers.Search.search(Search.java:216)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
Caused by: java.lang.IllegalArgumentException: Cannot reflectively create
enum objects
at
play.modules.elasticsearch.util.ReflectionUtil.newInstance(ReflectionUtil.java:268)


(Roland Quast) #2

Yes, I have found this odd problem just right now. I'm using the elasticsearch 0.4 module in play. Here's what I'm getting:

java.lang.IllegalArgumentException: Can not set models.FAQCategory field models.FAQ.category to java.lang.String
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:680)
at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:419)
at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:397)
at play.modules.elasticsearch.transformer.SimpleTransformer.toSearchResults(SimpleTransformer.java:75)
at play.modules.elasticsearch.Query.fetch(Query.java:190)
at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:145)
at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:96)
at controllers.Search.index(Search.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
at play.Invoker$Invocation.run(Invoker.java:278)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
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:722)

Any updates would be cool.. I don't know if I have to be concerned about it or not though?


(system) #3