【问题标题】:FOSElasticaBundle NumberFormatException error on populate填充时出现 FOSElasticaBundle NumberFormatException 错误
【发布时间】:2015-08-11 17:05:16
【问题描述】:

我在我的 Symfony 2 项目中使用 FOSElasticaBundle。由于今天重新索引导致以下错误:

index: /app/hotel/1 导致 MapperParsingException[解析失败 [价格来自]];嵌套:NumberFormatException [对于输入字符串: "410.00"];

在我的理论 orm yml 中,priceFrom 字段定义如下:

priceFrom:
   type: decimal
   nullable: true
   precision: 7
   scale: 2
   comment: ''
   column: price_from

我的fos_elastica 配置看起来像这样(config.yml):

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    app:                
        types:
            hotel:
                mappings:   
                    id: ~
                    active: ~                              
                    priceFrom: { type: integer }               
                persistence:
                    driver: orm
                    model: XXX\XXXBundle\Entity\Hotel
                    provider: ~
                    listener:
                        immediate: ~
                    finder: ~           

我用来重新索引的命令:php app/console fos:elastica:populate

到目前为止,上述设置一直有效。我希望有人能指出我解决这个问题的好方向。

版本: ruflin/elastica (2.1.0) Friendsofsymfony/elastica-bundle (v3.1.5) symfony/symfony (v2.6.11)

PS:我的项目中没有其他实体使用 priceFrom 字段。

【问题讨论】:

    标签: symfony foselasticabundle


    【解决方案1】:

    在映射中,您将 PriceFrom 定义为 integer,但随后您传递了一个 decimal

    我还没有测试过,但它肯定是罪魁祸首。

    【讨论】:

    • 我已经尝试将 priceFrom 映射更改为字符串或十进制,但同样的错误不断弹出。
    • 好的,请确保在更改后清除缓存。这可能不是最初问题的原因,但无论如何都需要解决。
    【解决方案2】:

    Francesco Abeni 的回答是正确的。如果您已经在 ES 中将某些内容推送为整数(或 ES 将其定义为整数),则当您尝试在此处保存十进制数据时会产生异常。

    我总是在映射中明确指定类型,例如:

     id: {"type" : "integer"}
     shop_id: {"type" : "integer"}
     source: {"type" : "string", "index" : "not_analyzed"}
    

    我看到了两种解决问题的方法。

    1. 索引别名和索引合并
    2. 在映射中指定类型;杀戮指数;再次填充

    我在 dev 上使用了第二个变体 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多