in Programming

Ignore fields at Elastic Search

While I was developing with the Play framework and Elastic Search, I faced a really annoying problem.

In my model I had a Date field. It seems that Elastic Search could not convert it to a valid format of it’s own and I got the following exception:

org.elasticsearch.index.mapper.MapperParsingException: Failed to parse [added]
	at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:309)
	at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:569)
	at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:441)
	at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:567)
	at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:491)
	at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:289)
	at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:185)
	at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:428)
	at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:341)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)
Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to parse date field, tried both date format [dateOptionalTime], and timestamp number
	at org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:343)
	at org.elasticsearch.index.mapper.core.DateFieldMapper.parseCreateField(DateFieldMapper.java:280)
	at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:296)
	... 11 more
Caused by: java.lang.IllegalArgumentException: Invalid format: "2012-03-01 00:00:00.0" is malformed at " 00:00:00.0"
	at org.elasticsearch.common.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:644)
	at org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:338)
	... 13 more

Since I didn’t want to search the Date field with Elastic Search at the first place, I found out I could set elastic search to ignore that field and since I’m only interested in searching the “name” and the “description” fields, I could add the @ElasticSearchIgnore annotation at all the other fields.

Now Elastic Search doesn’t bother to parse the Date field nor the others. To be honest, I didn’t found a solution for the Date conversion, but, hey, it works this way ;)

One feature I would like to see (I didn’t found out anything) is to be able to explicitly tell only which fields I want to be searched and exclude all the others.

Share