2

I am trying to setup a parent child relationship and I can't seem to get the mapping config right. I'm using Symfony2.5, FOSElastica 3.0.9 and Elasticsearch 1.4.4

Here is the relevent section from my mapping:

# fos elastica
fos_elastica:
    clients:
        default: { host: 127.0.0.1, port: 9200 }
    serializer: 
        callback_class: FOS\ElasticaBundle\Serializer\Callback
        serializer: serializer
    indexes:
        index:
            index_name: index_%kernel.environment%
            client: default
            types:
                company:
                    mappings:
                        id: 
                            type: "long"
                        company_name: 
                            type: "string"
                            fields:
                                raw:
                                    type: "string"
                                    index: "analyzed"
                                    index_analyzer: "sortable"
                    persistence:
                        elastica_to_model_transformer:
                            ignore_missing: true
                        driver: orm # orm, mongodb, propel are available
                        model: Alpha\RMSBundle\Entity\Company
                        provider: ~
                        finder: ~
                        listener: ~
                    serializer: 
                        groups: [company]
                job:
                    mappings:
                        id:
                            type: "long"
                        company:
                            type: "object"
                            properties:
                                id:
                                    type: "long"
                    _parent:
                        type: company
                        property: company
                        identifier: id
                    #_routing:
                    #    required: true
                    #    path: company
                    persistence:
                        elastica_to_model_transformer:
                            ignore_missing: true
                        driver: orm # orm, mongodb, propel are available
                        model: Alpha\RMSBundle\Entity\JobOpening
                        provider: ~
                        finder: ~
                        listener: ~
                    serializer: 
                        groups: [job]

First I populate company, but when I try to populate job I get the following error:

    [Elastica\Exception\ResponseException]                                 
  RoutingMissingException[routing is required for [index_v2]/[job]/[1]]

I have tried specifying the routing which is commented out above, but that didn't set the relationship either, I have taken the routing out as it is not mentioned in the docs. Can anyone see where I am going wrong?

4

2 に答える 2

2

上記のマッピングに問題はなく、_routing は必要ありません。ただし、FOSElastica はマッピングに _parent セットを設定しません。

ただし、ドキュメントに記載されているように、ドキュメントで setParent を使用する必要があります。これを行うには、カスタム ModelToElasticaTransformer をセットアップする必要があります。これは、クラス Alpha\RMSBundle\Transformer\JobToElasticaTransformer のバンドルから提供される ModelToElasticaAutoTransformer を拡張することで実行できます。

transform() 関数に次の行を挿入しました。

$document->setParent($object->getCompany()->getId());

すぐ真上に

return $document

次に、サービスを宣言します。

alpha.transformers.model.job:
    class:  Alpha\RMSBundle\Transformer\JobToElasticaTransformer
        calls:
            - [ setPropertyAccessor, ['@fos_elastica.property_accessor'] ]

最後に、persistence セクションのタイプのマッピングに次を追加します。

model_to_elastica_transformer:
    service: alpha.transformers.model.job

最初に親クラスに入力することを忘れない限り、通常どおり populate を使用できるようになりました

于 2015-04-16T08:48:45.957 に答える
1

バンドルは、ドキュメントでこれを非常に明確に説明しています

親を持つドキュメントを作成するには、_parent フィールドを設定するのではなく、ドキュメントで setParent を呼び出す必要があることに注意してください。これを間違って行うと、Elasticsearch は、親を持つべきドキュメントを保存する場所を認識していないが、それを指定していないため、RoutingMissingException が表示されます。

于 2015-04-10T22:46:07.800 に答える