I don't know how to map an array from a doctrine entity to elastic search. Indexation seems working for 1 but not for the second.
Here is my entity :
/**
* @var array $viewers
* @ORM\Column(name="permission_viewers", type="array", nullable=false)
*/
protected $viewers;
My elastic search config.yml
:
ged_document:
mappings:
name: { analyzer: default, type: string }
year: { analyzer: default, type: string }
author:
type: "object"
properties:
id: {analyzer: default, type: integer}
category:
type: "object"
properties:
id: {analyzer: default, type: integer}
name: {analyzer: whitespace, type: string}
parent:
type: "object"
properties:
id: {analyzer: default, type: integer}
onlyAuthor: {type: boolean}
name: {analyzer: whitespace, type: string}
viewers: {type: 'nested', index: not_analyzed}
The error I get when I try to index elastic search :
[2017-02-08 08:23:29,751][INFO ][cluster.metadata ] [Saint Anna] [[unadere]] remove_mapping [[ged_document]] [2017-02-08 08:23:29,772][INFO ][cluster.metadata ] [Saint Anna] [unadere] create_mapping [ged_document] [2017-02-08 08:23:29,865][DEBUG][action.bulk ] [Saint Anna] [unadere][2] failed to execute bulk item (index) index {[unadere][ged_document][37], source[{"name":"vente1","year":"2000","author":{"id":10004133},"category":{"id":10,"name":"Commande 1","parent":{"id":2,"onlyAuthor":true,"name":"Espace vente","viewers":["ROLE_UNADERE_CHARGE_DE_MISSION"]}},"tags":[],"breadcrumb":"Espace vente -> Commande 1"}]} org.elasticsearch.index.mapper.MapperParsingException: object mapping [viewers] trying to serialize a value with no field associated with it, current value [ROLE_UNADERE_CHARGE_DE_MISSION] at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:702) at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:497) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:706) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeNonDynamicArray(ObjectMapper.java:695) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeArray(ObjectMapper.java:604) at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:489) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeObject(ObjectMapper.java:554) at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:487) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeObject(ObjectMapper.java:554) at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:487) at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:544) at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493) at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:492) at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:409) at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:148) at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$PrimaryPhase.performOnPrimary(TransportShardReplicationOperationAction.java:574) at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$PrimaryPhase$1.doRun(TransportShardReplicationOperationAction.java:440) at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:36) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) [2017-02-08 08:23:29,873][INFO ][cluster.metadata ] [Saint Anna] [unadere] update_mapping [ged_document] (dynamic)
[Elastica\Exception\Bulk\ResponseException]
Error in one or more bulk request actions:
index: /unadere/ged_document/37 caused MapperParsingException[object mapping [viewers] trying to serialize a value with no field associated with it, current value [ROLE_UNADERE_CHARGE_DE_MISSION]]
How it looks like in DB :
Object 1 :
a:2{i:1;s:16:"ROLE_UNADERE_ACJ";i:0;s:30:"ROLE_UNADERE_CHARGE_DE_MISSION";}
Object 2 :
a:1:{i:0;s:30:"ROLE_UNADERE_CHARGE_DE_MISSION";}