ElasticSearch thinks my Map<String,String> should be datetime, and fails

I have a Java class:
public class Audit {
public Map<String,String> newValues = new HashMap<String,String>();
...
Which I turn to JSON:
{"newValues":{"data":"sjab",...},...}

I get this error
Failed to parse [newValues.data]

Caused by: org.elasticsearch.index.mapper.MapperParsingException: Failed to
parse [newValues.data]
at
org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:327)
at
org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:585)
at
org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:449)
at
org.elasticsearch.index.mapper.object.ObjectMapper.serializeObject(ObjectMapper.java:497)
at
org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:439)
at
org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493)
at
org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:437)
at
org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:311)
at
org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:202)
at
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)
at
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
... 1 more
Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to
parse date field [true], tried both date format [dateOptionalTime], and
timestamp number
at
org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:425)
at
org.elasticsearch.index.mapper.core.DateFieldMapper.parseCreateField(DateFieldMapper.java:354)
at
org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:314)
... 13 more
Caused by: java.lang.IllegalArgumentException: Invalid format: "true"
at
org.elasticsearch.common.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:747)
at
org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:419)

I tried putting various elements in schema.xml, but still get the error:


What to do?

(Other top-level fields work fine, but not the Strings in my map. It was
working earlier, then stopped!)

--Job

You can set the mapping for this field to String before sending the first doc.
I suppose that you sent a first doc with something like "2000-12" and that ES auto mapping thought it was a date.

So if you specify mapping first, ES will apply it.

HTH
David

--

Le 28 juil. 2012 à 00:10, job ob@b20nine.com a écrit :

I have a Java class:
public class Audit {
public Map<String,String> newValues = new HashMap<String,String>();
...
Which I turn to JSON:
{"newValues":{"data":"sjab",...},...}

I get this error
Failed to parse [newValues.data]

Caused by: org.elasticsearch.index.mapper.MapperParsingException: Failed to parse [newValues.data]
at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:327)
at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:585)
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:449)
at org.elasticsearch.index.mapper.object.ObjectMapper.serializeObject(ObjectMapper.java:497)
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:439)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:437)
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:311)
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:202)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
... 1 more
Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to parse date field [true], tried both date format [dateOptionalTime], and timestamp number
at org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:425)
at org.elasticsearch.index.mapper.core.DateFieldMapper.parseCreateField(DateFieldMapper.java:354)
at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:314)
... 13 more
Caused by: java.lang.IllegalArgumentException: Invalid format: "true"
at org.elasticsearch.common.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:747)
at org.elasticsearch.index.mapper.core.DateFieldMapper.parseStringValue(DateFieldMapper.java:419)

I tried putting various elements in schema.xml, but still get the error:


What to do?

(Other top-level fields work fine, but not the Strings in my map. It was working earlier, then stopped!)

--Job

Ah, auto mapping.

How do I set the type programmatically from Java? At the moment, I
inherited code like
client.prepareIndex(INDEX, "event", "abc123")
.setSource(json)
.execute()
.actionGet();

I'm a bit new here...

--Job

Have a look here : https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java

It should help.

--

Le 28 juil. 2012 à 01:11, job ob@b20nine.com a écrit :

Ah, auto mapping.

How do I set the type programmatically from Java? At the moment, I inherited code like
client.prepareIndex(INDEX, "event", "abc123")
.setSource(json)
.execute()
.actionGet();

I'm a bit new here...

--Job

https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616

Sorry. Line number was missing...

David

--

Le 28 juil. 2012 à 04:35, David Pilato david@pilato.fr a écrit :

Have a look here : https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java

It should help.

--

Le 28 juil. 2012 à 01:11, job ob@b20nine.com a écrit :

Ah, auto mapping.

How do I set the type programmatically from Java? At the moment, I inherited code like
client.prepareIndex(INDEX, "event", "abc123")
.setSource(json)
.execute()
.actionGet();

I'm a bit new here...

--Job