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(
	at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(
	at org.elasticsearch.index.mapper.object.ObjectMapper.parse(
	at org.elasticsearch.index.mapper.DocumentMapper.parse(
	at org.elasticsearch.index.mapper.DocumentMapper.parse(
	at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(
	at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
	at java.util.concurrent.ThreadPoolExecutor$
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(
	at org.elasticsearch.index.mapper.core.DateFieldMapper.parseCreateField(
	at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(
	... 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(
	at org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(
	... 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.