【问题标题】:Mapping definition has unsupported parameters: [store : true]映射定义具有不受支持的参数:[store : true]
【发布时间】:2015-12-20 17:54:32
【问题描述】:

我将我的索引ads 定义如下:

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: ~

仅供参考: 1. 这就是 Brend 与 User 与 @ManyToOne 的链接方式

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

仅供参考: 2. 我正在为 FOSElasticaBundle 和 Elastica 使用 dev-master 分支。对于elasticsearch,我使用的是2.1.1。

填充命令php app/console fos:elastica:populate 总是返回此错误:

[Elastica\Exception\ResponseException]
{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"[user] 的映射定义有不受支持的参数:[store : true]"}],"type":"mapper_parsing_exception","re​​ason" :"无法解析映射 [品牌]:
[user] 的映射定义具有不受支持的参数:[store : true]","caused_by":{"type":"mapper_parsing_exception","re​​ason":"[user] 的映射定义具有不受支持的参数:[store : true] "}}

我检查了app/logs/dev.log,发现为索引ads生成的映射有一个额外的参数"store":true。您可以检查一下:

[2015-12-20 21:28:21] elastica.DEBUG: 记录请求 {"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 ","启用":true}} []

下面是带有额外"store": true 的映射。有没有关于如何配置 FOSElasticaBundle 以在没有 "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!
                }
            }
        }
    }
}

【问题讨论】:

标签: symfony elasticsearch foselasticabundle


【解决方案1】:

MappingBuilder.php 中有一个错误,它会在 store property is not specified 时尝试添加 store: true。

您可以尝试明确指定store: false,以便!isset($property['store']) 测试失败:

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

您可以尝试的另一件事是修改私有 $skipTypes 数组以包含 nested 和 completion,这可以解决问题。

【讨论】:

  • store: false 没用!我刚刚评论了导致这个错误的代码。有公关!
  • 这就是我所担心的。 $skipTypes呢?
  • 我不明白你关于$skipTypes的解决方案...可以更新你的答案吗?
  • 在MappingBuilder.php(第24行)中,您可以尝试将nested添加到$skipTypes数组中,即private $skipTypes = array('completion','nested');
【解决方案2】:

这是 FOSElasticaBundle 中的一个错误。在这个PR 987中解决了。

您只需在Index/MappingBuilder.php 中评论与该错误相关的行!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多