mstein / elasticsearch-grails-plugin

ElasticSearch grails plugin
Based on Graeme Rocher initial stub. Note that it is still in early stage.
Other
62 stars 164 forks source link

Elasticsearch does not support BigDecimal as an object mapping #43

Closed djpentz closed 11 years ago

djpentz commented 11 years ago

I've hit a snag with using BigDecimal in a domain class, and the mapping that the plugin gives it in the ES schema. It maps it as type object, which ES doesn't seem to play nice with.

To deal with this issue, I started by creating an additional marshaller in JSONDomainFactory.DEFAULT_MARSHALLERS as follows:

/**
 * The default marshallers, not defined by user
 */
def static DEFAULT_MARSHALLERS = [
        (Map): MapMarshaller,
        (Collection): CollectionMarshaller,
        (BigDecimal): BigDecimalMarshaller
]

However this change is pointless because of the original mapping that the plugin does in ElasticSearchMappingFactory where my BigDecimal field is mapped to type 'object' there, and as such the marshalling still throws a stacktrace in ES when it tries to parse the JSON.

I asked about the BigDecimal issue on the ES mailing list here: https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/H74o1mNZXPk%5B1-25%5D and one of the regular contributors to ES has already submitted a pull request here: https://github.com/elasticsearch/elasticsearch/pull/2188 but this change has not made it into the 0.19.x branch. Hopefully it will be in the 0.20.x branch as Shannon has incorporated the pull request. But until then I need to address this issue in the ES Grails plugin. Does anybody have a good idea of how to fix this perhaps? I'm guessing that the best thing to do would be to give it a numeric mapping in ElasticSearchMappingFactory.getElasticMapping(SearchableClassMapping scm) where the property types are assigned an ES type. I'm going to forge ahead with a workaround but would appreciate any suggestions on a useful, orthogonal way to fix this.

Thanks, Darryl

djpentz commented 11 years ago

Not much movement on this plugin here anymore is there? :-(

v1p commented 11 years ago

Stuck with same problem here as well

v1p commented 11 years ago

Got this workaround that works for me (if type-checking in index is not kept strict) use this in searchable properties:

converter: 'string' where can be a BigDecimal.
pengqiuyuan commented 11 years ago

I also encountered the same problem for example, BigDecimal latitude, How do you do, thank you

v1p commented 11 years ago

@pengqiuyuan : latitude converter: 'string' Will certainly do the trick. I havn't digged into the converter code, though i assume this approach is fine for all the types, which support a .toString() method.

pengqiuyuan commented 11 years ago

@v1p : Yesterday, I solved the problem, methods, do not know if applicable to your project. I use es libraries without using elasticsearch-grails-plugin way of this project. Instead, a combination of elasticsearch-rft and spring-elasticsearch this two projects. client Transport beanlasticsearch:client id="esClient" esNodes="localhost:9300,localhost:9301" />

Overall the project is to es spun off from grails to connect to elasticsearch-rft

2013/7/12 v1p notifications@github.com

@pengqiuyuan https://github.com/pengqiuyuan : latitude converter: 'string' Will certainly do the trick. I havn't digged into the converter code, though i assume this approach is fine for all the types, which support a .toString() method.

¡ª Reply to this email directly or view it on GitHubhttps://github.com/mstein/elasticsearch-grails-plugin/issues/43#issuecomment-20840771 .

djpentz commented 11 years ago

Yeah I've abandoned the ES Grails plugin as well. Rather deal directly than through a middle man when the middle man doesn't seem to be alive. :-)

pengqiuyuan commented 11 years ago

It is not connected middleware? For example elaticsearch-rtf. My grails project is connected directly to a separate es library, a success. In gails the applicationContent.xml configuration and introduce it depends like, than the ES Grails plugin so that the effect is much better

2013/7/12 djpentz notifications@github.com

Yeah I've abandoned the ES Grails plugin as well. Rather deal directly than through a middle man when the middle man doesn't seem to be alive. :-)

— Reply to this email directly or view it on GitHubhttps://github.com/mstein/elasticsearch-grails-plugin/issues/43#issuecomment-20864606 .

v1p commented 11 years ago

I'll start on my own version of es-grails plugin after my project release, which is due in for next 2 weeks. Well yeah it's really great if you work straight with es libs, but then u'll end up putting more effort to get some obvious things working e.g domain classes sync.