1
votes

I defined my index ads as follows:

fos_elastica:
    clients:
         default: { host: %elastica_host%, port: %elastica_port% }         
    indexes:
          ads:
            types:                        
                brand:
                    mappings:
                        name:
                            type: string
                            boost: 5
                        slug:
                            type: string
                            boost: 4
                        date : ~
                        isPublished: ~
                        user:
                            type: nested
                            properties: 
                                username: ~
                                email: ~
                    persistence:
                        driver: orm
                        model: Minn\AdsBundle\Entity\Brend
                        elastica_to_model_transformer:
                            service: minn_ads.transformers_elastica.brand
                        provider: ~
                        listener:
                            immediate: ~
                        finder: ~

FYI: 1. This is how Brend is linked with User with @ManyToOne

/**
 * @ORM\ManyToOne(targetEntity="Minn\UserBundle\Entity\User")
 * @ORM\JoinColumn(nullable=false)
 */
private $user;

FYI: 2. I am using the dev-master branches for FOSElasticaBundle and Elastica. For elasticsearch, I am using 2.1.1.

A populate command php app/console fos:elastica:populate always returns this error:

[Elastica\Exception\ResponseException]
{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [user] has unsupported parameters: [store : true]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [brand]:
Mapping definition for [user] has unsupported parameters: [store : true]","caused_by":{"type":"mapper_parsing_exception","reason":"Mapping definition for [user] has unsupported parameters: [store : true]"}}

I checked the app/logs/dev.log, I found that the generated mapping for the index ads has an extra parameter "store":true. You can check that down:

[2015-12-20 21:28:21] elastica.DEBUG: logging Request {"path":"ads/","method":"PUT","data":{"mappings":{"brand":{"properties":{"name":{"type":"string","boost":5,"store":true},"slug":{"type":"string","boost":4,"store":true},"date":{"type":"string","store":true},"isPublished":{"type":"string","store":true},"user":{"type":"nested","properties":{"username":{"type":"string","store":true},"email":{"type":"string","store":true}},"store":true}},"dynamic_date_formats":[],"_meta":{"model":"Minn\AdsBundle\Entity\Brend"}}}},"query":[],"connection":{"config":{"headers":[]},"host":"127.0.0.1","port":9200,"logger":"fos_elastica.logger","enabled":true}} []

Below is the mapping with the extra "store": true. Is there any idea on how to configure FOSElasticaBundle to get a mapping without this extra line with "store": true ?

{
    "mappings": {
        "brand": {
            "properties": {
                "name": {
                    "type": "string",
                    "boost": 5,
                    "store": true
                },
                "slug": {
                    "type": "string",
                    "boost": 4,
                    "store": true
                },
                "date": {
                    "type": "string",
                    "store": true
                },
                "isPublished": {
                    "type": "string",
                    "store": true
                },
                "user": {
                    "type": "nested",
                    "properties": {
                        "username": {
                            "type": "string",
                            "store": true
                        },
                        "email": {
                            "type": "string",
                            "store": true
                        }
                    },
                    "store": true  # extra line! If deleted, it will work!
                }
            }
        }
    }
}
2
For those willing to follow, an issue has been opened in the FOSElasticaBundle Github repo.Val

2 Answers

2
votes

There's a bug in MappingBuilder.php which tries to add store: true whenever the store property is not specified.

What you could try is to explicitly specify store: false so that the !isset($property['store']) test fails:

                mappings:
                    name:
                        type: string
                        boost: 5
                    slug:
                        type: string
                        boost: 4
                    date : ~
                    isPublished: ~
                    user:
                        type: nested
                        store: false        <---
                        properties: 
                            username: ~
                            email: ~

Another thing you could try is to modify the private $skipTypes array to include nested in addition of completion, that could do the trick.

0
votes

This is a bug in the FOSElasticaBundle. It is solved in this PR 987.

You have just to comment the lines in Index/MappingBuilder.php related to that bug!